题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3732
#include <stdio.h>
#include <string.h>
#define MAXN 10002
int dp[MAXN],cnt[12][12],C;
void ZeroOnePack(int val,int complty)
{
int i;
for(i=C;i>=complty;--i)
if(dp[i]<dp[i-complty]+val)
dp[i]=dp[i-complty]+val;
}
void CompletePack(int val,int complty)
{
int i;
for(i=complty;i<=C;++i)
if(dp[i]<dp[i-complty]+val)
dp[i]=dp[i-complty]+val;
}
void MultPack(int val,int complty,int n)
{
int k;
if(complty*n>=C)
CompletePack(val,complty);
else
{
k=1;
while(k<n)
{
ZeroOnePack(k*val,k*complty);
n-=k;
k*=2;
}
ZeroOnePack(n*val,n*complty);
}
}
int main()
{
int n,i,j,k;
char word[12];
while(scanf("%d %d",&n,&C)!=EOF)
{
memset(cnt,0,sizeof(cnt));
memset(dp,0,sizeof(dp));
for(k=0;k<n;++k)
{
scanf("%s %d %d",word,&i,&j);
cnt[i][j]++;//相同 value and complexity的单词数
}
for(i=0;i<11;++i)
{
for(j=0;j<11;++j)
if(cnt[i][j])
MultPack(i,j,cnt[i][j]);
}
printf("%d\n",dp[C]);
}
return 0;
}