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 fac671c commit 22b2d3bCopy full SHA for 22b2d3b
Solutions/[12]_2.cpp
@@ -0,0 +1,28 @@
1
+import java.util.Scanner;
2
+
3
+public class Main {
4
5
+ public static void main(String[] args) {
6
+ Scanner sc = new Scanner(System.in);
7
8
+ int n = sc.nextInt();
9
+ int k = sc.nextInt();
10
+ int[][] dp = new int[n + 1][k + 1];
11
12
+ for (int i = 1; i <= n; i++) {
13
+ int weight = sc.nextInt();
14
+ int value = sc.nextInt();
15
+ for (int j = 1; j <= k; j++) {
16
+ if (j < weight) {
17
+ dp[i][j] = dp[i - 1][j];
18
+ }
19
+ else {
20
+ dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - weight] + value);
21
22
23
24
25
+ System.out.println(dp[n][k]);
26
27
28
+}
0 commit comments