天天看点

LightOJ 1232 Coin Change (II)(完全背包)

C - Coin Change (II) Time Limit:1000MS    Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1232

Description

In a strange shop there are n types of coins of value A1, A2 ... An. You have to find the number of ways you can makeK using the coins. You can use any coin at most K times.

For example, suppose there are three coins 1, 2, 5. Then if K = 5 the possible ways are:

11111

1112

122

5

So, 5 can be made in 4 ways.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing two integers n (1 ≤ n ≤ 100) andK (1 ≤ K ≤ 10000). The next line contains n integers, denotingA1, A2 ... An (1 ≤ Ai ≤ 500). AllAi will be distinct.

Output

For each case, print the case number and the number of ways K can be made. Result can be large, so, print the result modulo100000007.

Sample Input

2

3 5

1 2 5

4 20

1 2 3 4

Sample Output

Case 1: 4

Case 2: 108

题意:n种硬币,要得到k个硬币,每种硬币最多用k次,求方案数

思路:完全背包统计

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int dp[10005];
int main()
{
    int t,n,k,a[105],m=1;
    cin>>t;
    while(t--)
    {
        scanf("%d%d",&n,&k);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
            //清零
            memset(dp,0,sizeof(dp));
            dp[0]=1;
            //控制格式
         if(m++)
            printf("Case %d: ",m-1);

            for(int i=1;i<=n;i++)//枚举物品的种类
            {
                for(int j=a[i];j<=k;j++)//枚举背包数量
                {
                     dp[j]=(dp[j]+dp[j-a[i]])%100000007;
                }
            }
            printf("%d\n",dp[k]);
    }
    return 0;
}