Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- const int maxn = 1005;
- typedef long long ll;
- const ll MOD = 1e9 + 7;
- int main()
- {
- ios_base::sync_with_stdio(false);
- int n, K;
- cin >> n >> K;
- vector<int> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- }
- vector<ll> dp(K + 1);
- dp[0] = 1;
- for(int at = 0; at < n; at++) {
- for(int used_candies = K; used_candies >= 0; used_candies--) {
- ll tmp = dp[used_candies];
- int L = used_candies + 1;
- int R = used_candies + min(v[at], K - used_candies);
- for(int i = L; i <= R; i++) {
- dp[i] += tmp;
- dp[i] %= MOD;
- }
- // for(int candy = 1; candy <= min(v[at], K - used_candies); candy++) {
- // dp[used_candies + candy] += tmp;
- // dp[used_candies + candy] %= MOD;
- // }
- }
- }
- cout << dp[K] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment