삼성 모의 테스트 수영장문제입니다.
재귀함수를 잘 구현하면 됩니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include <iostream> using namespace std; int cost[4]; int month[13] = { 0, }; int ans; void money(int mon, int totalmoney) { if (mon > 12) { if (totalmoney < ans) ans = totalmoney; return; } if (month[mon]) { //1일 이용권 if(month[mon]*cost[0]<cost[1]) money(mon + 1, totalmoney + month[mon] * cost[0]); //한 달 이용권 else money(mon + 1, totalmoney + cost[1]); //세 달 이용권 money(mon + 3, totalmoney + cost[2]); } else money(mon + 1, totalmoney); } int main() { int T; cin >> T; for (int test_case = 1; test_case <= T; test_case++) { cin >> cost[0] >> cost[1] >> cost[2] >> cost[3];//1일 한달 3달 1년 for (int i = 1; i <= 12; i++) { cin >> month[i]; } ans = cost[3]; money(1, 0); cout << '#' << test_case << ' ' << ans << '\n'; } } | cs |
'알고리즘 > 구현 및 시뮬레이션' 카테고리의 다른 글
[B10752] - Cow Hopscotch (0) | 2018.09.22 |
---|---|
[B10025] - 게으른 백곰 (0) | 2018.09.22 |
[B10656] - 십자말풀이 (0) | 2018.09.21 |
[B9873] - Cow Baseball (0) | 2018.09.21 |
[S2382] - [모의 SW 역량테스트] 미생물 격리 (0) | 2018.08.26 |