Skip to content

Commit

Permalink
14501 퇴사 / 다이나믹 프로그래밍
Browse files Browse the repository at this point in the history
  • Loading branch information
cjy8922 authored May 2, 2021
1 parent 2cf7064 commit 7c2c697
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 2021_05/BJ_14501.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

int n;
cin >> n;

int T[15];
int P[15];
vector<int> res(15);

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

for (int i = n-1; i >= 0; i--) {
if (i + T[i] > n) res[i] = res[i + 1];
else res[i] = max(res[i + 1], res[i + T[i]] + P[i]);
}

cout << res[0] << endl;
return 0;
}

0 comments on commit 7c2c697

Please sign in to comment.