Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stdio.h>
- #include<string.h>
- #include<math.h>
- #define mod 100000007
- //5 /5 8 11 15 18 /18 using one coin several time
- //how many ways it can be created
- using namespace std;
- int n,cap;
- int val[102];
- int num[102];
- bool flag;
- int dp[102][1002][25];
- int coin(int i,int w,int c)
- {
- if(w==0)
- {
- return 1;
- }
- if(i>=n)
- {
- if(w==0)
- {
- return 1;
- }
- else if(w!=0)
- {
- return 0;
- }
- }
- if(dp[i][w][c]!=-1)
- {
- return dp[i][w][c];
- }
- int ret1,ret2;
- ret1=ret2=0;
- if(w-val[i]>=0)
- {
- if(c<num[i])
- {
- ret1=coin(i,w-val[i],c+1)%mod;
- }
- }
- ret2=coin(i+1,w,0)%mod;
- dp[i][w][c]=(ret1+ret2)%mod;
- return dp[i][w][c];
- }
- int main()
- {
- int i,j,k,t;
- // 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent
- scanf("%d",&t);
- for(int kk1=1;kk1<=t;kk1++)
- {
- scanf("%d %d",&n,&cap);
- for(i=0;i<n;i++)
- {
- scanf("%d",&val[i]);
- }
- for(i=0;i<n;i++)
- {
- scanf("%d",&num[i]);
- }
- memset(dp,-1,sizeof(dp));
- printf("Case %d: ",kk1);
- printf("%d\n",(coin(0,cap,0)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement