Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int n;
- // 0 is right
- // 1 is left
- void use_int_dfs(int index, int cur_state = 0, int cur_sum = 0) {
- if (cur_sum < 0) return;
- if (index == 2 * n) {
- if (cur_sum != 0) return;
- for (int i = 0;i < 2 * n;++i)
- cout << ((cur_state>>i&1) ? '(' : ')');
- cout << '\n';
- return;
- }
- // put ')'
- use_int_dfs(index+1, cur_state, cur_sum - 1);
- // put '('
- use_int_dfs(index+1, cur_state | (1<<index), cur_sum + 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement