提交时间:2023-12-09 08:41:41

运行 ID: 114719

#include<iostream> using namespace std; const int N = 50, M = 1e2 * 2 + 10; int n, m, f[M], w[N], v[N]; int main(){ cin >> m >> n; for(int i = 1; i <= n; i++){ cin >> w[i] >> v[i]; } for(int i = 1; i <= n; i++){ for(int j = 0; j <= m; j++){ if(j >= w[i]){ f[j] = max(f[j], f[j-w[i]] + v[i]); } } } cout << f[m]; return 0; }