fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int MOD = 1e9 + 7;
  5. const int N = 1e5 + 5;
  6.  
  7.  
  8. int n, w;
  9. int a[105];
  10. ll dp[N], prfx[2][N];
  11.  
  12.  
  13. ll pfx(int u, int v, int x)
  14. {
  15. return ((prfx[x][v + 1] % MOD) - (prfx[x][u] % MOD) + MOD) % MOD;
  16. }
  17.  
  18.  
  19. int main() {
  20. ios_base::sync_with_stdio(false); cin.tie(NULL);
  21.  
  22. cin >> n >> w;
  23.  
  24. for (int i = 1; i <= n; i++) cin >> a[i];
  25.  
  26. memset(dp, 0, sizeof(dp));
  27. for (int i = 1; i <= w + 1; i++) prfx[0][i] = 1;
  28. prfx[0][0] = 0; prfx[1][0] = 0; prfx[1][1] = 1;
  29. dp[0] = 1;
  30.  
  31. for (int i = 1; i <= n ; i++)
  32. {
  33. int y, x; y = i % 2; x = 1 - y;
  34. for (int j = 1; j <= w; j++)
  35. {
  36. dp[j] = pfx(max(0, j - a[i]), j, x);
  37. prfx[y][j + 1] = ((prfx[y][j] % MOD) + dp[j]) % MOD;
  38. }
  39. }
  40.  
  41. cout << dp[w];
  42.  
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
stdout
1