fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. int n, a[100];
  7. int prod, sum;
  8.  
  9. int32_t main() {
  10. cin >> n; int ans = 0;
  11. for(int i = 0; i < n; i++) cin >> a[i];
  12. cin >> prod >> sum;
  13. for(int mask = 0; mask < (1<<n); mask++){
  14. int P=1, S=0;
  15. for(int i = 0; i < n; i++){
  16. if(mask>>i&1){
  17. if(P>prod/a[i]) { P=prod+1; break; }
  18. P*=a[i],S+=a[i];
  19. }
  20. }
  21. if(P==prod and S==sum) ans++;
  22. }
  23. cout << ans << "\n";
  24. }
  25.  
Success #stdin #stdout 0.01s 5328KB
stdin
5
2 2 3 4 2
16 8
stdout
3