585 if(level == 0 && !stage) {
592 pair<int, int> nexts[4] = {pair(x - 1, y), pair(x + 1, y), pair(x, y - 1),
595 bool picked_cpy[5][5];
596 memcpy(picked_cpy, picked,
sizeof picked_cpy);
599 picked_cpy[x][y] =
true;
601 for(
const auto next: nexts) {
602 if(0 <= next.first && next.first < n && 0 <= next.second && next.second < n &&
603 !picked_cpy[next.first][next.second]) {
605 if(stage && horseshoes[next.first][next.second] ==
'(') {
606 res =
dfs(
true, horseshoes, picked_cpy, count + 1, level + 1, next.first, next.second, n);
607 }
else if(stage && horseshoes[next.first][next.second] ==
')') {
608 res =
dfs(
false, horseshoes, picked_cpy, count + 1, level - 1, next.first, next.second, n);
609 }
else if(!stage && horseshoes[next.first][next.second] ==
')') {
610 res =
dfs(
false, horseshoes, picked_cpy, count + 1, level - 1, next.first, next.second, n);
static int dfs(bool stage, char horseshoes[5][5], const bool picked[5][5], int count, int level, int x, int y, int n)