题解 | #采药#
采药
http://www.nowcoder.com/practice/d7c03b114f0541dd8e32ce9987326c16
#include<iostream> using namespace std; const int N = 1010; int f[N]; int n, m; int main(){ while(cin >> m >> n){ for(int i = 0, v, w; i < n; i ++ ){ 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; }