-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1535.cpp
More file actions
53 lines (39 loc) · 946 Bytes
/
1535.cpp
File metadata and controls
53 lines (39 loc) · 946 Bytes
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include <string>
using namespace std;
int N;
int happy[20];
int hp[20];
int dp[101][20];
int rec(int now, int nowHp) {
if (now == N) {
if (dp[nowHp][now] == -1)return 0;
else return dp[nowHp][N - 1];
}
if (dp[nowHp][now] != -1)return dp[nowHp][now];
int val = rec(now + 1, nowHp);
if (nowHp - hp[now] > 0) {
val = max(val,rec(now+1, nowHp - hp[now])+happy[now]);
}
dp[nowHp][now] = val;
return val;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N;
fill(&dp[0][0], &dp[100][20], -1);
for (int i = 0; i < N; i++) {
cin >> hp[i];
}
for (int i = 0; i < N; i++) {
cin >> happy[i];
}
int val = rec(0, 100);
if (val == -1)cout << "0";
else cout << val;
}