[BOJ] 9663번 N-Queen

yeham·2022년 11월 9일
0

백준

목록 보기
10/22

문제

N-Queen

코드

#include <iostream>
#include <cmath>

using namespace std;

int n;
int m = 0;
bool check1[15];
bool check2[30];
bool check3[30];

void ft_check(int count)
{
	if (count == n)
	{
		m++;
		return ;
	} 
	for (int i = 0; i < n; i++)
	{
		if (check1[i] == 1 || check2[i + count] == 1 || check3[i - count + 15] == 1)
			continue;
		check1[i] = 1;
		check2[i + count] = 1;
		check3[i - count + 15] = 1;
		ft_check(count + 1);
		check1[i] = 0;
		check2[i + count] = 0;
		check3[i - count + 15] = 0;
	}
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	ft_check(0);
	cout << m;
	return (0);
}
profile
정통과 / 정처기 & 정통기 / 42seoul 7기 Cardet / 임베디드 SW 개발자

0개의 댓글