Advertisement
shawon_majid

dp5

May 1st, 2022
1,052
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. //Bismillahir Rahman-ir Rahim
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define debug(x) cout << '>' << #x << " : " << x << endl;
  5. #define all(c) c.begin(), c.end()
  6. #define F first
  7. #define S second
  8. #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  9. typedef unsigned long long ull;
  10. typedef long long ll;
  11.  
  12. vector < int > coins;
  13. int n;
  14.  
  15. const int mod = 1e9+7;
  16.  
  17. int dp[105][1000000];
  18.  
  19. int ways(int i, int sum){
  20.     if(sum < 0) return 0;
  21.     if(sum == 0) return 1;
  22.     if(sum != 0 and i <= 0){
  23.         return 0;
  24.     }
  25.     if(dp[i][sum] != -1) return dp[i][sum];
  26.  
  27.     return dp[i][sum] =  ((ways(i-1, sum) % mod) + (ways(i, sum - coins[i-1]) % mod)) % mod;
  28.  
  29. }
  30.  
  31. int main(){
  32.  
  33.     memset(dp, -1, sizeof dp);
  34.  
  35.     int x;
  36.     cin >> n >> x;
  37.  
  38.     for(int i = 0; i < n; i++){
  39.         int c;
  40.         cin >> c;
  41.         coins.push_back(c);
  42.     }
  43.  
  44.     cout << ways(n, x) << endl;
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement