dp之多重背包hdu1114
题目很水,不多说.........
#include<stdio.h> int main() { long t,n,m,a,i,j,dp[10005],vol[505],jizhi[505],sum,w; scanf("%ld",&t); while(t--) { w=0; scanf("%ld%ld",&n,&m); sum=m-n; scanf("%ld",&a); for(i=0;i<a;i++) { scanf("%ld%ld",&jizhi[i],&vol[i]); if(vol[i]<=sum) w=1; } if(w==0) printf("This is impossible.\n"); else { for(i=0;i<10005;i++) dp[i]=10000000; dp[0]=0; for(i=0;i<a;i++) for(j=vol[i];j<=sum;j++) if(dp[j]>dp[j-vol[i]]+jizhi[i]) dp[j]=dp[j-vol[i]]+jizhi[i]; if(dp[sum]<10000000) printf("The minimum amount of money in the piggy-bank is %ld.\n",dp[sum]); else printf("This is impossible.\n"); } } return 0; }
朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。