Light OJ 1232 Coin Change (II)

1232 - Coin Change (II)
Time Limit: 1 second(s)Memory Limit: 32 MB

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 make K 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) and K (1 ≤ K ≤ 10000). The next line contains n integers, denoting A1, A2 ... An (1 ≤ Ai ≤ 500). All Ai 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 modulo 100000007.

Sample Input

Output for Sample Input

2

3 5

1 2 5

4 20

1 2 3 4

Case 1: 4

Case 2: 108

 

题意和上题一样,只不过背包容量的范围变成了10000,每种物品的数量也是10000数量级

#include <cstdio>
#include <cstring>
using namespace std;

const int mod = 100000007;
int dp[101][10001];
int a[10001], sum[10001];
int main()
{
    int t, n, m, cas = 1;
    scanf("%d", &t);
    while (t--){
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; i++)
            scanf("%d", &a[i]);
        memset (dp, 0, sizeof(dp));
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++){
            for (int j = 0; j <= m; j++){
                sum[j] = 0;
                if (j - a[i] >= 0)
                    sum[j] += sum[j - a[i]];
                sum[j] += dp[i - 1][j];
                sum[j] %= mod;
                if (j - a[i] >= 0)
                    dp[i][j] += sum[j - a[i]];
                dp[i][j] += dp[i - 1][j];
                dp[i][j] %= mod;
            }
        }
        printf("Case %d: %d\n", cas++, dp[n][m]);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值