1024. 装箱问题
题目链接
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
int v, n;
cin >> v >> n;
int a;
int dp[20010] = { 0 };
for (int i = 1; i <= n; i++) {
cin >> a;
for (int j = v; j >= a; j--) {
dp[j] = max(dp[j], dp[j - a] + a);
}
}
cout << v-dp[v];
return 0;
}