[SWEA] 수영장

rhkr9080·2022년 10월 14일
0

문제링크 : https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PpFQaAQMDFAUq

#include <iostream>
#include <cstring>
using namespace std;

int ticket[4];
int plan[12];
int used[12];
int minCost;

void DFS(int month, int cost)
{
	if (minCost <= cost) return;
	if (month >= 12)
	{
		if (minCost > cost) minCost = cost;
		return;
	}
	if (plan[month] == 0) {
		DFS(month + 1, cost);
	}
	else {
		DFS(month + 1, cost + ticket[0] * plan[month]);
		DFS(month + 1, cost + ticket[1]);
		DFS(month + 3, cost + ticket[2]);
	}
}

void INIT()
{
	memset(ticket, 0, sizeof(ticket));
	memset(plan, 0, sizeof(plan));
	minCost = 2134567890;
}

void INPUT()
{	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	for (int i = 0; i < 4; i++)
		cin >> ticket[i];
	minCost = ticket[3];
	for (int i = 0; i < 12; i++)
		cin >> plan[i];
}

void SOLVE()
{
	DFS(0, 0);
}

int main()
{
	int T;
	cin >> T;
	for (int tc = 1; tc <= T; tc++)
	{
		INIT();
		INPUT();
		SOLVE();
		cout << "#" << tc << " " << minCost << "\n";
	}
}
profile
공부방

0개의 댓글