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];
- void add_mod(int &a, int b) {
- a += b;
- if(a >= mod) {
- a -= mod;
- }
- }
- void subtract_mod(int &a, int b) {
- a -= b;
- if(a < 0) {
- a += mod;
- }
- }
- 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++) {
- vector<int> pref_sum(k + 5, 0);
- 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);
- if(start <= end) {
- add_mod(pref_sum[start], memo[chocolates_left]);
- subtract_mod(pref_sum[end + 1], memo[chocolates_left]);
- }
- }
- int sum = 0;
- for(int j = 0; j <= k; j++) {
- add_mod(sum, pref_sum[j]);
- add_mod(memo[j], sum);
- }
- }
- cout << memo[k] << endl;
- return 0;
- }
- // min(1, )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement