提交时间:2023-04-08 11:24:39
运行 ID: 73676
#include <iostream> #include <algorithm> using namespace std; int a[35], b[35][20005] = {0}; int main() { int v, n; cin >> v >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) for (int j = 1; j <= v; j++) { if (a[i] > j) b[i][j] = b[i-1][j]; else b[i][j] = max(b[i - 1][j], b[i - 1][j - a[i]] + a[i]); } cout << v - b[n][v] << endl; }