Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <cstring>
- using namespace std;
- int n,k;
- const int mod = 1e9 + 7;
- int a[105];
- int memo[100005];
- int main() {
- cin >> n >> k;
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- }
- memset(memo,0,sizeof(memo));
- memo[0] = 1; // memo[i] - broj na nacini da stigneme so i candies
- for(int at = 0; at < n; at++) {
- for(int chocolates_left = k; chocolates_left >= 0; chocolates_left--) {
- int start = chocolates_left + 1;
- int end = chocolates_left + min(a[at], k - chocolates_left);
- for(int j = start; j <= end; j++) {
- memo[j] += memo[chocolates_left];
- memo[j] %= mod;
- }
- }
- }
- cout << memo[k] << endl;
- return 0;
- }
- // min(1, )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement