Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

注意输出格式啊!

Posted by chenxuan123456789 at 2012-07-29 10:03:57 on Problem 1384
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator