bhupixb

Subset generation using Recursion

Sep 28th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. // I can't tell you what it really is,
  2. // I can only tell you what it feels like.
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5.  
  6. typedef long long ll;
  7. int n = 3;
  8.  
  9. int solve(int i, int mask) {
  10. if (i == n) {
  11. int temp = mask;
  12. for (int j = 0; mask; ++j, mask /= 2) {
  13. if (mask & 1) {
  14. // Do Something here
  15. }
  16. }
  17. return __builtin_popcount(0);
  18. }
  19. return max(solve(i+1, mask|(1<<i)), solve(i+1, mask));
  20. }
  21.  
  22. int main() {
  23. // cin >> n;
  24. cout << solve(0,0);
  25. }
Add Comment
Please, Sign In to add comment