Advertisement
Josif_tepe

Untitled

Feb 18th, 2022
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <cstring>
  5. using namespace std;
  6. int n,k;
  7. const int mod = 1e9 + 7;
  8. int a[105];
  9. int memo[100005];
  10.  
  11. int main() {
  12.     cin >> n >> k;
  13.     for (int i = 0; i < n; i++) {
  14.         cin >> a[i];
  15.     }
  16.     memset(memo,0,sizeof(memo));
  17.     memo[0] = 1; // memo[i] - broj na nacini da stigneme so i candies
  18.     for(int at = 0; at < n; at++) {
  19.         for(int chocolates_left = k; chocolates_left >= 0; chocolates_left--) {
  20.             int start = chocolates_left + 1;
  21.             int end = chocolates_left + min(a[at], k - chocolates_left);
  22.             for(int j = start; j <= end; j++) {
  23.                     memo[j] += memo[chocolates_left];
  24.                     memo[j] %= mod;
  25.             }
  26.         }
  27.     }
  28.    
  29.         cout << memo[k] << endl;
  30.     return 0;
  31. }
  32. // min(1, )
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement