We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 337006d commit 2a244a7Copy full SHA for 2a244a7
Appendix E/12865.cpp
@@ -0,0 +1,31 @@
1
+// http://boj.kr/485b69efb085449ca4c64d848656498b
2
+#include <bits/stdc++.h>
3
+using namespace std;
4
+
5
+int n, k;
6
+int d[102][100002];
7
+int w[102];
8
+int v[102];
9
10
+int main(void) {
11
+ ios::sync_with_stdio(0);
12
+ cin.tie(0);
13
14
+ cin >> n >> k;
15
+ for(int i = 0; i < n; i++)
16
+ cin >> w[i] >> v[i];
17
18
+ for(int i = 0; i < n; i++){
19
+ for(int j = 1; j <= k; j++){
20
+ if(i-1 >= 0)
21
+ d[i][j] = d[i-1][j];
22
+ if(j-w[i] >= 0){
23
24
+ d[i][j] = max(d[i][j], d[i-1][j-w[i]] + v[i]);
25
+ else
26
+ d[i][j] = v[i];
27
+ }
28
29
30
+ cout << d[n-1][k];
31
+}
0 commit comments