Advertisement
Josif_tepe

Untitled

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