/*
分析:
多重背包&&二进制。
n最大为10W,容量为1W,所以正常的0-1背包坑定的TLE。
发现0<=v、c<=10,最多有100种组合(而且v==0的10种组
合还不用考虑),所以转化成多重背包就行了。
另外,由于每种组合的情况数可能过多,所以同时还要配
合上二进制的思想(至于这个二进制的思想的话,可以看看
hdu2844这个题:
http://blog.csdn.net/ice_crazy/article/details/8668896)
2013-03-19
*/
分析:
多重背包&&二进制。
n最大为10W,容量为1W,所以正常的0-1背包坑定的TLE。
发现0<=v、c<=10,最多有100种组合(而且v==0的10种组
合还不用考虑),所以转化成多重背包就行了。
另外,由于每种组合的情况数可能过多,所以同时还要配
合上二进制的思想(至于这个二进制的思想的话,可以看看
hdu2844这个题:
http://blog.csdn.net/ice_crazy/article/details/8668896)
2013-03-19
*/
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
const int N=10011;
int dp[N];
int hash[11][11];
int main()
{
int i,l,j;
int n,m;
char str[22];
int a,b,k,temp;
while(scanf("%d%d",&n,&m)!=-1)
{
memset(hash,0,sizeof(hash));
for(i=0;i<n;i++)
{
scanf("%s%d%d",str,&a,&b);
hash[a][b]++;
}
memset(dp,0,sizeof(dp));
for(i=1;i<11;i++)
for(l=0;l<11;l++)
{
if(!hash[i][l]) continue;
/*****/ //这部分用二进制
k=1;
while(hash[i][l]>=k)
{
for(j=m;j>=k*l;j--)
{
temp=dp[j-k*l]+k*i;
if(dp[j]<temp) dp[j]=temp;
}
hash[i][l]-=k;
k<<=1;
}
if(hash[i][l])
{
k=hash[i][l];
for(j=m;j>=k*l;j--)
{
temp=dp[j-k*l]+k*i;
if(dp[j]<temp) dp[j]=temp;
}
}
/*****/
}
printf("%d\n",dp[m]);
}
return 0;
}