提交时间:2023-12-02 07:57:47
运行 ID: 113252
#include<bits/stdc++.h> using namespace std; int f[105][1005],w[105]; int main(){ int n,capa; cin>>capa>>n; for (int i = 1;i <= n;i++){ cin>>w[i]; } for (int i = 1;i <= n;i++){ for (int j = capa;j >= 0;j--){ if (j >= w[i]){ f[i][j] = max(f[i - 1][j - w[i]] + w[i],f[i - 1][j]); } else{ f[i][j] = f[i - 1][j]; } } } cout<<capa - f[n][capa]<<endl; return 0; }