생각하는데 시간은 오래 걸렸지만 한번에 맞추긴 했다
감 잡을 때 까지 화이팅
#include <iostream>
#define MAX 987654321
using namespace std;
int TC, result;
int month[13];
int dayPmonth[13]; //달 별 운동 일 수
int cost[4]; //1일치, 1달치, 3달치, 1년치
void Init() {
for (int i = 1; i < 13; i++) {
month[i] = MAX;
dayPmonth[i] = 0;
}
for (int i = 0; i < 4; i++) {
cost[i] = 0;
}
}
void Enter() {
for (int i = 0; i < 4; i++) {
cin >> cost[i];
}
for (int i = 1; i < 13; i++) {
cin >> dayPmonth[i];
}
}
void Print() {
for (int i = 1; i <= 12; i++) {
cout << month[i] << ' ';
}
cout << '\n';
}
int Solve() {
for (int i = 1; i <= 12; i++) {
int newCost = 0;
for (int j = 0; j < 3; j++) {
if (i <= 2 && j == 2) { //1,2월은 3개월 이전이 없기에 break
break;
}
if (j == 0) { //1일치
newCost = dayPmonth[i] * cost[j];
}
else if (j == 1) { //1달치
if (dayPmonth[i]) {
newCost = cost[j];
}
}
else if (j == 2) { //3달치
if (dayPmonth[i]) {
newCost = cost[j];
if (month[i] > month[i - 3] + newCost) {
month[i] = month[i - 3] + newCost;
}
}
}
if (j != 2) {
if (month[i] > month[i - 1] + newCost) {
month[i] = month[i - 1] + newCost;
}
}
}
//Print();
}
if (month[12] > cost[3]) {
month[12] = cost[3];
}
return month[12];
}
int main() {
cin >> TC;
for(int i=1;i<=TC;i++) {
Init(); //month, cost 초기화
Enter(); // 값 입력
result = Solve();
cout << "#" << i << ' ' << result << '\n';
}
}
