Advertisement
Josif_tepe

Untitled

Mar 18th, 2021
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n;
  6. int niza[105];
  7. int memo[1000005];
  8. const int MOD = 1000000007;
  9.  
  10. int main()
  11. {
  12.     int x;
  13.     cin >> n >> x;
  14.     for(int i = 0; i < n; i++) {
  15.         cin >> niza[i];
  16.     }
  17.     for(int i = 0; i <= x; i++) {
  18.         memo[i] = 0;
  19.     }
  20.     memo[0] = 1;
  21.     for(int sum = 0; sum <= x; sum++) {
  22.         for(int i = 0; i < n; i++) {
  23.             if(sum + niza[i] <= x) {
  24.                 memo[sum + niza[i]] += memo[sum];
  25.                 memo[sum + niza[i]] %= MOD;
  26.             }
  27.         }
  28.     }
  29.     cout << memo[x] << endl;
  30.     return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement