문제
https://swexpertacademy.com/main/code/problem/problemList.do?
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
풀이
DP라기엔 점화식도 없고 구현에 가깝다고 생각한다.
그냥 해당 빌딩을 기준으로 양옆 +-2의 MAX를 찾아서 뺴주기만 해도 금방 나오는 문제다.
소스 코드
#include<iostream>
using namespace std;
int N;
int num, result;
string str;
void DFS(int n, int cur) {
if (cur == num) {
result = max(result, stoi(str));
return;
}
for (int i = n; i < str.size() - 1; i++) {
for (int j = i + 1; j < str.size(); j++) {
swap(str[i], str[j]);
DFS(i, cur + 1);
swap(str[i], str[j]);
}
}
}
int main(int argc, char** argv)
{
int test_case;
int T;
cin>>T;
for(test_case = 1; test_case <= T; ++test_case)
{
result = 0;
cin >> str >> num;
if (str.size() < num)
num = str.size();
DFS(0, 0);
cout << "#" << test_case << " " << result << '\n';
}
return 0;
}
'Programming Practice > SWEA' 카테고리의 다른 글
[SWEA] 1249. 보급로 - D4 (0) | 2022.05.10 |
---|---|
[SWEA] 1954. 달팽이 - D2 (0) | 2022.05.10 |
[SWEA] 1206. View - D3 (0) | 2022.05.02 |
[SWEA] 1859. 백만장자 프로젝트 - D2 (0) | 2022.05.02 |
[SWEA] 1204. 최빈수 구하기 - D2 (0) | 2022.05.02 |