Posts 15486 퇴사2
Post
Cancel

15486 퇴사2

15486 퇴사2

코드

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
34
35
#include <iostream>

using namespace std;

int N, T[1500000], P[1500000], DP[1500000];

int dp(int deep);
int max(int a, int b) {
	return a > b ? a : b;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> T[i] >> P[i];
	}

	cout << dp(0);
}

int dp(int deep) {
	if (deep >= N)
		return 0;
	if (DP[deep] != 0)
		return DP[deep];

	int result = 0;
	if (deep + T[deep] <= N)
		result = dp(deep + T[deep]) + P[deep];
	result = max(result, dp(deep + 1));

	return DP[deep] = result;
}
This post is licensed under CC BY 4.0 by the author.

14891 Samsung sw test

15683 Samsung sw test

Comments powered by Disqus.