提交时间:2023-12-02 08:15:00
运行 ID: 113270
#include<bits/stdc++.h> using namespace std; int main(){ int n,m; scanf("%d%d",&n,&m); int vi[1001],pi[1001]; int dp[1001][1001]; for(int i = 1;i <= n;i++){ scanf("%d%d",&vi[i],&pi[i]); } for(int i = 1;i <= n;i++){ for(int j = 0;j <= m;j++){ if(j >= vi[i]){ dp[i][j] = max(dp[i-1][j-vi[i]]+pi[i],dp[i-1][j]); }else{ dp[i][j] = dp[i-1][j]; } } } printf("%d",dp[n][m]); return 0; }