sandeep03edu

Coin Combinations II

Jul 30th, 2022
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define MOD 1000000007;
  5.  
  6. #define got cout<<"YES\n"; return;
  7. #define got0 cout<<"YES\n"; return 0;
  8.  
  9. #define bhak cout<<"NO\n"; return;
  10. #define bhak0 cout<<"NO\n"; return 0;
  11.  
  12. #define bas cout<<"\n";
  13.  
  14. vector<vector<ll>> dp(101, vector<ll> (1e6+10, -1));
  15.  
  16. ll getAns(ll i, ll sum, ll n, vector<ll> &vec){
  17.     if(sum==0){
  18.         return 1;
  19.     }
  20.    
  21.     if(sum<0){
  22.         return 0;
  23.     }
  24.  
  25.     if(i==n){
  26.         return 0;
  27.     }
  28.  
  29.     if(dp[i][sum]!=-1){
  30.         return dp[i][sum];
  31.     }
  32.    
  33.     ll pick = getAns(i, sum-vec[i], n, vec)%MOD;
  34.     ll notPick = getAns(i+1, sum, n, vec)%MOD;
  35.    
  36.     return dp[i][sum] = (pick + notPick)%MOD;
  37. }
  38.  
  39. int main() {
  40.     // your code goes here
  41.     ll  n, sum; cin>>n>>sum;
  42.     vector<ll> vec(n);
  43.     for(ll i=0; i<n; ++i){
  44.         cin>>vec[i];
  45.     }
  46.  
  47.     ll ans = getAns(0, sum, n, vec);
  48.    
  49.     cout<<ans;
  50.     bas
  51.    
  52.     return 0;
  53. }
  54.  
Add Comment
Please, Sign In to add comment