N-Queens


解けなかった.

https://programmers.co.kr/learn/courses/30/lessons/12952
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int col[13] = { 0, };
int LoopSize(0);
int answer(0);

bool chk(int Depth)
{
    for (int i = 0; i < Depth; i++)
    {
        if ((abs(Depth - i) - abs(col[Depth] - col[i]) == 0) || (col[Depth] == col[i]))//대각선분 또는
        {
            return false;
        }
    }
    return true;
}

void dfs(int Depth)
{
    if (Depth == LoopSize)
    {
        answer++;
        return;
    }

    for (int i = 0; i < LoopSize; i++)
    {
        col[Depth] = i;

        if (true == chk(Depth))
        {
            dfs(Depth + 1);
            col[Depth] = 0;
        }
    }
}


int solution(int n) {
 
    LoopSize = n;


    dfs(0);

    return answer;
}

[バックグラウンドトレースのクリーンアップ]
完全ナビゲーションをベースとした構成でDPとは異なる

最初も.
for (int i = 0; i < arr_size; i++)
	{
		Col[col] = i;//한 열에 해당되는곳 모두 탐색
		if (check(Col[col]))
		{
			backtracking(col + 1);//다음 열 투입한다.
		}
	}
砲口を元に図中に展開するように遡及(再帰)する
関数の内部から延びる条件でない場合は、falseをすぐに返します.
これにより、写真中にX字で表示されている内容が生成されます.