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.

31 lines
577 B

#include <bits/stdc++.h>
using namespace std;
const int N = 30010;
int n, m;
int f[N];
/*
将原问题做如下转化
总钱数相当于背包总容量
每件物品的价格相当于体积
每件物品的价格乘以重要度相当于价值
那么就变成了经典的01背包问题。
*/
int main() {
cin >> m >> n;
for (int i = 0; i < n; i++) {
int v, w;
cin >> v >> w;
w *= v;
for (int j = m; j >= v; j--)
f[j] = max(f[j], f[j - v] + w);
}
cout << f[m] << endl;
return 0;
}