提交时间:2023-12-09 08:53:08
运行 ID: 114750
#include<iostream> using namespace std; const int N = 50, M = 210; int n, m, f[M], w[N], v[N]; int main(){ cin >> m >> n; for(int i = 1; i <= n; i++){ cin >> v[i] >> w[i]; } for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ if(v[i] <= j){ f[j] = max(f[j], f[j-v[i]] + w[i]); } } } cout << f[m]; return 0; }