nqueen

    [골5] 9663 - N-Queen

    #include using namespace std; int n, answer = 0; int vis[15]{ 0 }; // 유망한지 체크 bool Check(int cnt) { for (int i = 0; i < cnt; i++) { auto vis1 = vis[cnt], vis2 = vis[i]; if (vis1 == vis2 || cnt - i == abs(vis1 - vis2)) return 0; } return 1; } void BackTracking(int cnt) { if (cnt == n) { answer++; return; } for (int i = 0; i < n; i++) { vis[cnt] = i; if (Check(cnt)) BackTracking(cnt + 1); } } int ..