Skip to content

Commit 5950db4

Browse files
committed
feat: 1535 안녕 풀이
1 parent 10d6ae1 commit 5950db4

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

2주차 Knapsack/양효인/1535.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <iostream>
2+
#include <vector>
3+
using namespace std;
4+
5+
int L[20];
6+
int J[20];
7+
int n;
8+
int life;
9+
10+
int maxJoy(int i, int life) {
11+
if (life <= 0) return -1e9;
12+
if (i >= n) return 0;
13+
14+
int skip = maxJoy(i + 1, life);
15+
int take = J[i] + maxJoy(i + 1, life - L[i]);
16+
17+
return max(skip, take);
18+
}
19+
20+
int main() {
21+
ios::sync_with_stdio(false);
22+
cin.tie(NULL); cout.tie(NULL);
23+
24+
life = 100;
25+
cin >> n;
26+
27+
for (int i = 0; i < n; i++) {
28+
cin >> L[i];
29+
}
30+
for (int i = 0; i < n; i++) {
31+
cin >> J[i];
32+
}
33+
34+
int joy = maxJoy(0, life);
35+
cout << joy;
36+
37+
return 0;
38+
}

0 commit comments

Comments
 (0)