fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. #define ld long double
  6. #define all(x) (x).begin(), (x).end()
  7. #define debug(x) cerr << #x << " = " << (x) << endl;
  8.  
  9. const int MOD = 1e9 + 7;
  10. const int INF = 1e18;
  11. const ld PI = acos(-1.0);
  12.  
  13. int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
  14. int lcm(int a, int b) { return a / gcd(a, b) * b; }
  15.  
  16. void solve() {
  17. int n,y;
  18. cin >> n >> y;
  19.  
  20. vector<int>b(n);
  21. for(int i=0;i<n;i++)cin>> b[i];
  22.  
  23. int sum=accumulate(b.begin(),b.end(),0);
  24. vector<vector<int>>dp(n+1,vector<int>(y+1));
  25.  
  26. for (int i=0; i<=n; i++) dp[i][0] = 1;// 1 way-> not taking anything to make sum=0
  27.  
  28. for(int i=1;i<=n;i++){
  29. for(int j=1;j<=y;j++){
  30. dp[i][j]=(j-b[i-1]>=0 ? dp[i-1][j-b[i-1]]:0)+dp[i-1][j];
  31. }
  32. }
  33. cout<<dp[n][y]<<endl;
  34. }
  35.  
  36. int32_t main() {
  37. ios::sync_with_stdio(false);
  38. cin.tie(nullptr);
  39. solve();
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 5268KB
stdin
7 5
3 2 1 4 3 5 -2
stdout
69