Created
August 6, 2019 02:04
-
-
Save surinoel/b2c5681b4d5a587c0c7907eef9ec80c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment