zju2014 Piggy-Bank

zju2014 Piggy-Bank

#include < iostream >
using   namespace  std;

int  n,v;
int  f[ 10010 ];
int  main()
{
    
int  t;
    scanf(
" %d " , & t);
    
while (t -- ){
        
int  v1;
        scanf(
" %d%d%d " , & v1, & v, & n);
        v
-= v1;
        memset(f,
0x7F , sizeof (f));
        f[
0 ] = 0 ;
        
for ( int  i = 1 ;i <= n; ++ i){
            
int  w,c;
            scanf(
" %d%d " , & c, & w);
            
for ( int  j = w;j <= v; ++ j)
                
if (f[j] > f[j - w] + c)
                    f[j]
= f[j - w] + c;
        }
        
if (f[v] >= 0xFFFFFFF ) printf( " This is impossible.\n " );
        
else  printf( " The minimum amount of money in the piggy-bank is %d.\n " ,f[v]);
    }
    
return   0 ;
}




你可能感兴趣的:(zju2014 Piggy-Bank)