fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxN = 1000005;
  4. int n, M;
  5. int a[maxN];
  6. int X[maxN] = {0};
  7. int rescount = 0;
  8. void solve(int idx, int current_sum) {
  9. if (idx > n) {
  10. if (current_sum == M){
  11. rescount++;
  12. }
  13. return;
  14. }
  15. int remain = 0;
  16. for(int i = idx + 1; i <= n; i++) {
  17. remain += a[i];
  18. }
  19. int rangbuoc = (M - current_sum - remain) / a[idx];
  20. for(int i = 1; i <= rangbuoc; i++) {
  21. X[idx] = i;
  22. solve(idx + 1, current_sum + a[idx] * i);
  23. X[idx] = 0;
  24. }
  25. }
  26. int main() {
  27. cin >> n >> M;
  28. for(int i = 1; i <= n; i++) {
  29. cin >> a[i];
  30. }
  31. solve(1, 0);
  32. cout << rescount;
  33. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
1