Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
注意输出格式啊!#include <stdio.h> #include <string.h> #define INF 9999999 #define M 10000+10 int min(int a,int b) { return a>b?b:a; } int kind[505][2]; int e1,f1; int f[M]; int main() { int cases,i,j,k; scanf("%d",&cases); while(cases--) { scanf("%d %d",&e1,&f1); scanf("%d",&k); for(i=1;i<=k;i++) scanf("%d %d",&kind[i][0],&kind[i][1]); f[0]=0; for(i=1;i<M;i++) f[i]=INF; for(i=1;i<=k;i++) { for(j=1;j<=f1-e1;j++) if(j>=kind[i][1]) f[j]=min(f[j],f[j-kind[i][1]]+kind[i][0]); } if(f[f1-e1]==INF) printf("This is impossible.\n"); else printf("The minimum amount of money in the piggy-bank is %d.\n",f[f1-e1]); } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator