Advertisement
Kevin_Zhang

Untitled

Feb 1st, 2022
1,373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. int n;
  2. // 0 is right
  3. // 1 is left
  4. void use_int_dfs(int index, int cur_state = 0, int cur_sum = 0) {
  5.     if (cur_sum < 0) return;
  6.     if (index == 2 * n) {
  7.         if (cur_sum != 0) return;
  8.         for (int i = 0;i < 2 * n;++i)
  9.             cout << ((cur_state>>i&1) ? '(' : ')');
  10.         cout << '\n';
  11.         return;
  12.     }
  13.     // put ')'
  14.     use_int_dfs(index+1, cur_state, cur_sum - 1);
  15.     // put '('
  16.     use_int_dfs(index+1, cur_state | (1<<index), cur_sum + 1);
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement