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