1952 수영장
2019. 8. 6. 11:04ㆍ알고리즘/백준
모든 경우의 수를 탐색해서 최솟값을 찾는 문제. 완전탐색은 dfs로 처리를 했다
문제: https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PpFQaAQMDFAUq
깃허브주소: https://github.com/surinoel/boj/blob/master/swea1952.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstring> | |
#include <iostream> | |
using namespace std; | |
#define min(n, m) n > m ? m : n | |
int price[4]; | |
int month[13]; | |
void go(int idx, int sum, int &ans) { | |
if (idx > 12) { | |
ans = min(ans, sum); | |
return; | |
} | |
if (month[idx] == 0) { | |
go(idx + 1, sum, ans); | |
} | |
else { | |
go(idx + 1, sum + price[0] * month[idx], ans); | |
go(idx + 1, sum + price[1], ans); | |
go(idx + 3, sum + price[2], ans); | |
} | |
return; | |
} | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int tc; | |
cin >> tc; | |
for (int test_case = 1; test_case <= tc; test_case++) { | |
for (int i = 0; i < 4; i++) { | |
cin >> price[i]; | |
} | |
for (int i = 1; i <= 12; i++) { | |
cin >> month[i]; | |
} | |
int ans = 1e8; | |
go(0, 0, ans); | |
ans = min(ans, price[3]); | |
cout << "#" << test_case << " " << ans << '\n'; | |
} | |
return 0; | |
} |
'알고리즘 > 백준' 카테고리의 다른 글
15685 드래곤 커브 (0) | 2019.08.09 |
---|---|
14888 연산자 끼워넣기 (0) | 2019.08.07 |
1188 음식 평론가 (0) | 2019.08.05 |
3023 마술사 이민혁 (0) | 2019.08.04 |
10174 펠린드롬 (0) | 2019.08.03 |