题解 | #装箱问题#
装箱问题
https://www.nowcoder.com/practice/c990bd0bf8e04bfbb19c0964401c8f77
#include <algorithm> #include <iostream> using namespace std; const int N = 2 * 10010; int a[N], f[N]; int main() { int m, n; cin >> m >> n; for(int i = 1; i <= n; i ++) cin >> a[i]; for(int i = 1; i <= n; i ++) for(int j = m; j >= a[i]; j --) { f[j] = max(f[j], f[j - a[i]] + a[i]); } cout << m - f[m] << endl; return 0; }