题解
2023-08-20 14:33:19
发布于:广东
12阅读
0回复
0点赞
也还好,不算很难
#include <bits/stdc++.h>
using namespace std;
const int maxn = 20010;
int dp[31][maxn];
int v[maxn];
int main() {
int V, n;
cin >> V >> n;
for (int i = 1; i <= n; ++i) {
cin >> v[i];
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= V; ++j) {
dp[i][j] = dp[i - 1][j];
if (j >= v[i]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - v[i]] + v[i]);
}
}
}
cout << V - dp[n][V] << endl;
return 0;
}
这里空空如也
有帮助,赞一个