BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草
题意:完全背包
题解:完全背包
代码:
#include<cstdio> #include<algorithm> using namespace std; int f[100005],p[105],c[105]; int main(){ int n,h; scanf("%d%d",&n,&h); for (int i=1; i<=n; i++) scanf("%d%d",&p[i],&c[i]); for (int i=1; i<=2*h; i++) f[i]=1e9; for (int i=0; i<=2*h; i++) for (int j=1; j<=n; j++) if (i>=p[j]) f[i]=min(f[i],f[i-p[j]]+c[j]); int minn=1e9; for (int i=h; i<=2*h; i++) minn=min(minn,f[i]); printf("%d\n",minn); return 0; }