标签:
#include<stdio.h>
#include<string.h>
struct Case{
int price,importance;
}data[25];
int main(){
int N,m,T,bag[30000],a,b;
scanf("%d",&T);
while(T--){memset(bag,0,sizeof(bag));
scanf("%d%d",&N,&m);
for(int i=0;i<m;++i)scanf("%d%d",&a,&b),data[i].price=a,data[i].importance=a*b;
for(int i=0;i<m;++i){
for(int j=N;j>0;j--){
if(j>=data[i].price){
if(bag[j-data[i].price]+data[i].importance>bag[j])bag[j]=bag[j-data[i].price]+data[i].importance; }
}
}
printf("%d\n",bag[N]);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4529274.html