疯狂的采药
传送门:https://www.luogu.org/problemnew/show/P1616
完全背包
#include<cstdio> #include<algorithm> using namespace std; inline int read() { static char ch; while((ch = getchar()) < '0' || ch > '9'); int ret = ch - 48; while((ch = getchar()) >= '0' && ch <= '9') ret = ret * 10 + ch - 48; return ret; } int t,m,v[10001],w[10001],f[100001]; int main() { t = read(); m = read(); for(int i = 1;i <= m;i++) { w[i] = read(); v[i] = read(); } for(int i = 1;i <= m;i++) { for(int j = w[i];j <= t;j++) { f[j] = max(f[j],f[j-w[i]] + v[i]); } } printf("%d",f[t]); return 0; }