第12届蓝桥杯赛国赛 小蓝买瓜子

#include <bits/stdc++.h>

using namespace std;

const int N = 1010;
int n, m;
int v[N], w[N];
int f[N];
/**
 测试用例:
 80 2
 18 10
 30 20
 */

//完全背包问题
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 = v[i]; j <= m; j++)
            f[j] = max(f[j], f[j - v[i]] + w[i]);

    cout << f[m] << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/littlehb/p/15601527.html