Posts 14501 Samsung sw test
Post
Cancel

14501 Samsung sw test

14501 Samsung sw test

코드

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
#include <iostream>
#define MAX_DAY 15

using namespace std;

int day;
int time[MAX_DAY];
int proceeds[MAX_DAY];

int DP(int d, int proceed);
int max(int a, int b);

int main() {
	cin >> day;
	for (int i = 0; i < day; i++)
		cin >> time[i] >> proceeds[i];

	cout << DP(0, 0);
 }

int DP(int d, int proceed) {
	if (d >= day)
		return proceed;

	int a = 0;
	if (day - d >= time[d])
		a = DP(d + time[d], proceed + proceeds[d]);
	return max(a, DP(d + 1, proceed));
}

int max(int a, int b) {
	return a > b ? a : b;
}
This post is licensed under CC BY 4.0 by the author.

13460 Gold 2

14502 Samsung sw test

Comments powered by Disqus.