백준
1. 다이나믹 프로그래밍
n = int(input())
t = []
p = []
dp = [0] * (n + 1)
max_value = 0
for _ in range(n):
x, y = map(int, input().split())
t.append(x)
p.append(y)
for i in range(n - 1, -1, -1):
time = t[i] + i
if time <= n:
dp[i] = max(p[i] + dp[time], max_value)
max_value = dp[i]
else:
dp[i] = max_value
print(max_value)
2. C++
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> t;
vector<int> p;
int dp[16];
int maxValue;
int main(void) {
cin >> n;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
t.push_back(x);
p.push_back(y);
}
for (int i = n - 1; i >= 0; i--) {
int time = t[i] + i;
if (time <= n) {
dp[i] = max(p[i] + dp[time], maxValue);
maxValue = dp[i];
}
else dp[i] = maxValue;
}
cout << maxValue << '\n';
}