题目连接:https://www.luogu.com.cn/problem/P1616
是一道动态规划中完全背包问题的模板题
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>using namespace std;const int N = 10000010;int n, m;
long long f[N];int main() {
cin >> m >> n;for (int i = 0; i < n; i ++ ) {
int v, w; cin >> v >> w;for (int j = v; j <= m; j ++ ) f[j] = max(f[j], f[j - v] + w);}cout << f[m] << endl;return 0;
}