标签:blog http io ar os sp for 数据 div
1 1000 5 800 2 400 5 300 5 400 3 200 2
3900
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
struct nn
{
int v,p; //v是价格,p是重要度
}a[26];
int dp[30000];
int main()
{
int i,j,n,t,m;
scanf("%d",&t);
while(t--)
{
memset(dp,0,sizeof(dp));
scanf("%d%d",&n,&m);//n是钱数,m是物品个数
for(i=1;i<=m;i++)
{
scanf("%d%d",&a[i].v,&a[i].p);
for(j=n;j>=a[i].v;j--)
dp[j]=max(dp[j],dp[j-a[i].v]+a[i].p*a[i].v);
}
printf("%d\n",dp[n]);
}
return 0;
}
标签:blog http io ar os sp for 数据 div
原文地址:http://www.cnblogs.com/a972290869/p/4099968.html