Mirbek

Coin Combinations II

Dec 22nd, 2021
1,197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 1e6 + 3;
  6. const int mod = 1e9 + 7;
  7.  
  8. int n, x;
  9. int dp[N], a[N];
  10.  
  11. int main(){
  12.     cin >> n >> x;
  13.  
  14.     for (int i = 1; i <= n; i++) {
  15.         cin >> a[i];
  16.     }
  17.  
  18.     dp[0] = 1;
  19.  
  20.     for (int i = 1; i <= n; i++) {
  21.         for (int j = 1; j <= x; j++) {
  22.             if (j - a[i] >= 0) {
  23.                 dp[j] = (dp[j] + dp[j - a[i]]) % mod;
  24.             }
  25.         }
  26.     }
  27.  
  28.     cout << dp[x] << endl;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment