#include<cstdio>
#include<algorithm>
#include<cstring>
#define MAX(x,y) ((x)>(y)?(x):(y))
using namespace std;
int dp[5050][2];
int w[1000];
int main()
{
int n,col,T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&col);
for(int i=1;i<=n;i++)
scanf("%d",&w[i]);
for(int i=0;i<=col;i++)
{
dp[i][0]=0;
dp[i][1]=1;
}
for(int i=1;i<=n;i++)
{
for(int j=col;j>=w[i];j--)
{
if(dp[j][0]<dp[j-w[i]][0]+1)
{
dp[j][0]=dp[j-w[i]][0]+1;
dp[j][1]=dp[j-w[i]][1];
}
else
{
if(dp[j][0]==dp[j-w[i]][0]+1)
{
dp[j][1]=dp[j][1]+dp[j-w[i]][1];
}
}
}
}
if(dp[col][0])
printf("You have %d selection(s) to buy with %d kind(s) of souvenirs.\n",dp[col][1],dp[col][0]);
else
printf("Sorry, you can't buy anything.\n");
}
}
hdu 2126 求方案数
最新推荐文章于 2020-03-19 11:27:56 发布