// aarifshuvo ``CSEJU #include <bits/stdc++.h> #define ll long long #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define REP(i,n) for(int i=0;i<n;i++) #define REV(i,n) for(int i=n-1;i>=0;i--) #define FOR(i,a,b) for(int i=a;i<=b;i++) #define pri(a) cout<<a<<endl using namespace std; ll coins[52], times[52]; ll n,k; ll dp[52][1008]; ll call(ll i, ll feas) { if(feas==0) return 1; if(i==n) return 0; if(dp[i][feas]!=-1) return dp[i][feas]; dp[i][feas] = 0; for(int j=0; j<=times[i] && feas-j*coins[i]>=0 ;j++) { dp[i][feas] += call(i+1,feas-j*coins[i])%100000007; } return dp[i][feas]%100000007; } int main() { ll T,cs=0; scanf("%lld", &T); while(T--) { memset(dp, -1, sizeof dp); scanf("%lld%lld", &n, &k); REP(i,n) scanf("%lld", &coins[i]); REP(i,n) scanf("%lld", ×[i]); printf("Case %lld: %lld\n", ++cs, call(0,k)); } return 0; }
~Be glad of life because it gives you the chance to love and to work and to play and to look at the stars.~
Thursday, June 1, 2017
LightOJ 1231 Coin Change(I)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment