提交时间:2023-12-02 08:45:58
运行 ID: 113300
#include<iostream> using namespace std; const int N = 50, M = 20010; int m, n, f[M], v[N], w[N]; int main(){ cin >> m >> n; for(int i = 1; i <= n; i++){ cin >> w[i]; v[i] = w[i]; } for(int i = 1; i <= n; i++){ for(int j = m; j >= 0; j--){ if(j >= w[i]){ f[j] = max(f[j], f[j-w[i]] + v[i]); } } } cout << m - f[m]; return 0; }