| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- 루아
- c언어 배열 programming
- N Queen Coordinates
- 온라인 비주얼 스튜디오
- c언어 콘서트 배열 2번
- c언어 콘서트 배열
- 루아다운로드
- 메이플스토리
- c샾 헬로우 월드
- c언어 최대최소
- 2중 반복문
- 비주얼 스튜디오 다운로드
- Lua 설명
- 비주얼 스튜디오
- LUA
- N Queen 문제
- lua download
- C언어 달력
- c#온라인
- for문
- c sharp hello world
- Lua란
- 게임제작
- c언어 버블정렬
- N Queens Problem
- Lua language
- lua 다운로드
- c샾 hello world
- 유니티
- c++ 등차수열 합
Archives
- Today
- Total
Ln Go
N Queen Algorithm 본문
#include <iostream>
#include <cmath> //double type value absolute
#include <cstdlib> //int type value absolute
using namespace std;
int board[20], cnt;
void add(int n)
{
++cnt;
}
int place(int row, int column)
{
int i;
for(i = 1; i <=row -1; i++)
{
if (board[i] == column)
{
return 0;
}
else
{
if (abs(board[i] - column) == abs(i - row)) //기울기의 절대값
{
return 0;
}
}
}
return 1;
}
void queen(int row, int n)
{
int column;
for(column = 1; column <= n; ++column)
{
if(place(row, column)) //place return == 1 이면
{
board[row] = column;
if(row == n)
{
add(n); // find solution => call add fuction
}
else
{
queen(row +1, n); // not find solution => call queen(row + 1, n); Recursive Fuction
}
}
}
}
int main() {
int n;
cin >> n;
queen(1,n);
cout << "N Queen Algorithm "<< cnt <<endl;
return 0;
}'c++' 카테고리의 다른 글
| vector 선언 3종류 (0) | 2022.06.28 |
|---|---|
| c++ 문자열 대문자로 출력 (0) | 2021.09.15 |
| Online Compile Site (0) | 2021.06.03 |
| C++ 2중 for문 등차수열 합 출력 (0) | 2021.05.01 |
| 비쥬얼 스튜디오 다운로드 (0) | 2020.04.13 |
Comments