import java.util.Scanner;
//01背包问题
public class test7 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int c = sc.nextInt();
int[][] dp = new int[n+1][c+1];
int[] w = new int[n];
int[] v = new int[n];
for(int i=0;i<n;i++){
w[i]=sc.nextInt();
v[i]=sc.nextInt();
}
for(int i=0;i<n;i++){
for(int j=0;j<=c;j++){
if(j<w[i])
dp[i+1][j]=dp[i][j];
else
dp[i+1][j]=Math.max(dp[i][j], dp[i][j-w[i]]+v[i]);
}
}
System.out.println(dp[n][c]);
}
}
01背包
最新推荐文章于 2024-09-08 11:09:43 发布