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 |
PROBLEM SETTER: JANE ALAM JAN
这个类属于完全背包,但不明白那个最多用k次到底能干什么。
-----
如果value为1,此时value最小,那么最多可以用k个,所以可以看成完全背包。
#include<bits/stdc++.h>
# define ll long long
using namespace std;
const ll mod=100000007;
const int N=1e5+10;
int num[N];
int a[N];//价值
ll dp[N];
int main()
{
int t;
cin>>t;
for(int o=1;o<=t;o++)
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
memset(dp,0,sizeof(dp));
dp[0]=1;
for(int i=1;i<=n;i++)
{
for(int k=a[i];k<=m;k++)
{
dp[k]=(dp[k]+dp[k-a[i]])%mod;
}
}
printf("Case %d: %d\n",o,dp[m]%mod);
}
}