-
[C++] ์ผ์ฑ 1952. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ์์์ฅ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:14728x90
๋ชจ๋ ๊ฒฝ์ฐ์ ์ ๊ตฌํด๋ณด๊ธฐ
#include<iostream> #include<vector> using namespace std; int cost[4] = {0, }; int month[12] = {0, }; int min_cost = 99999999; void solution(int index, int total) { if (index >= 12) { if (min_cost > total) min_cost = total; return; } solution(index + 1, total + cost[0] * month[index]); solution(index + 1, total + cost[1]); solution(index + 3, total + cost[2]); } int main() { int T; cin >> T; for (int t = 1; t <= T; t++) { for (int i = 0; i < 4; i++) { cin >> cost[i]; } for (int i = 0; i < 12; i++) { cin >> month[i]; } min_cost = 99999999; solution(0, 0); solution(12, cost[3]); cout << "#" << t << " " << min_cost << endl; } return 0; }
728x90'์ฝ๋ฉํ ์คํธ > ์ฝ๋ฉํ ์คํธ ์ฐ์ต' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C++] ์ผ์ฑ 4014. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ํ์ฃผ๋ก ๊ฑด์ค (0) 2020.10.27 [C++] ๋ฐฑ์ค 9372๋ฒ. ์๊ทผ์ด์ ์ฌํ (0) 2020.10.27 [C++] ์ผ์ฑ 2382. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ๋ฏธ์๋ฌผ ๊ฒฉ๋ฆฌ (0) 2020.10.27 [C++] ๋ฐฑ์ค 9935๋ฒ. ๋ฌธ์์ด ํญ๋ฐ (0) 2020.10.27 [C++] ์ผ์ฑ 2383. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ์ ์ฌ ์์ฌ์๊ฐ (0) 2020.10.27