提交时间:2024-04-06 14:24:45
运行 ID: 141874
#include<bits/stdc++.h> #define int long long using namespace std; int dp[35][20005],a[20005]; signed main(){ int n,v; cin>>v>>n; for (int i = 1;i <= n;i++){ cin>>a[i]; } for (int i = 1;i <= n;i++){ for (int j = 0;j <= v;j++){ dp[i][j] = dp[i - 1][j]; if (j >= a[i]){ dp[i][j] = max(dp[i][j],dp[i - 1][j - a[i]] + a[i]); } } } cout<<v - dp[n][v]; return 0; }