Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- int n;
- int k;
- int niza[105];
- int dp[100005];
- using namespace std;
- int main()
- {
- cin>>n;
- cin>>k;
- int mod = 1e9 + 7;
- for(int i=0; i<n; i++){
- cin>>niza[i];
- }
- for(int j=0; j<=k; j++){
- dp[j] = 0;
- }
- dp[0] = 1;
- // dp[j] --> broj na nacini da stigneme so j candies
- for(int i = 0; i < n; i++) {
- vector<int> pref_sum(k + 10, 0);
- for(int j = k; j >= 0; j--) {
- int x = j + 1, y = j + min(niza[i], k - j);
- if(x <= y) {
- pref_sum[x] += dp[j];
- pref_sum[x] %= mod;
- pref_sum[y + 1] -= dp[j];
- if(pref_sum[y + 1] < 0) {
- pref_sum[y + 1] += mod;
- }
- }
- }
- int sum = 0;
- for(int j = 0; j <= k; j++) {
- sum += pref_sum[j];
- sum %= mod;
- dp[j] += sum;
- dp[j] %= mod;
- }
- }
- cout << dp[k] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement