HDU 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
#include<stdio.h>
#include<string.h>
int nvalue , m ;
int price[110] , weigt[110] , num[110] , fine[110] = {0} ;
int main ()
{
int cas ;
scanf ( "%d" , &cas ) ;
while ( cas -- )
{
memset( fine , 0 , sizeof(fine) ) ;
scanf ( "%d%d" , &nvalue , &m ) ;
for ( int i = 0 ; i < m ; ++ i )
scanf ( "%d%d%d" , price+i , weigt+i , num+i ) ;
for ( int i = 0 ; i < m ; ++ i )
for ( int j = 0 ; j < num[i] ; ++ j )
for ( int k = nvalue ; k >= price[i] ; -- k )
{
if ( fine[k] < fine[k-price[i]] + weigt[i] )
fine[k] = fine[k-price[i]] + weigt[i] ;
}
printf ( "%d\n" , fine[nvalue] ) ;
}
return 0 ;
}
#include<string.h>
int nvalue , m ;
int price[110] , weigt[110] , num[110] , fine[110] = {0} ;
int main ()
{
int cas ;
scanf ( "%d" , &cas ) ;
while ( cas -- )
{
memset( fine , 0 , sizeof(fine) ) ;
scanf ( "%d%d" , &nvalue , &m ) ;
for ( int i = 0 ; i < m ; ++ i )
scanf ( "%d%d%d" , price+i , weigt+i , num+i ) ;
for ( int i = 0 ; i < m ; ++ i )
for ( int j = 0 ; j < num[i] ; ++ j )
for ( int k = nvalue ; k >= price[i] ; -- k )
{
if ( fine[k] < fine[k-price[i]] + weigt[i] )
fine[k] = fine[k-price[i]] + weigt[i] ;
}
printf ( "%d\n" , fine[nvalue] ) ;
}
return 0 ;
}