You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
548 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<bits/stdc++.h>
using namespace std;
/*
知识点内容:动态规则完全背包
文档内容参考:
https://www.cnblogs.com/aiguona/p/7274876.html
*/
using namespace std;
int w[300], c[300], f[300010];
int V, n;
int main() {
scanf("%d%d", &V, &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &w[i], &c[i]);
}
for (int i = 1; i <= n; i++)
for (int j = w[i]; j <= V; j++)//注意此处与0-1背包不同这里为顺序0-1背包为逆序
f[j] = max(f[j], f[j - w[i]] + c[i]);
printf("max=%d\n", f[V]);
return 0;
}