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.

22 lines
545 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;
const int N = 1010;
int m, n;
int f[N];
// 经典01背包
// 采药总时间相当于背包容量,每一株药相当于一件物品,采药时间相当于该物品的体积,草药的价值相当于物品价值。
int main() {
cin >> m >> n;
for (int i = 0; i < n; i++) {
int v, w; // v体积w价值
cin >> v >> w;
for (int j = m; j >= v; j--)
f[j] = max(f[j], f[j - v] + w);
}
cout << f[m] << endl;
return 0;
}