|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include <iostream>
- #include <cstring>
- #define N 15
- using namespace std;
- int table[N] = {0};
- int count = 0;
- //x行, y列
- bool check(int x, int y)
- {
- //行不用检察
- for(int i=0; i<x; i++)
- {
- if(table[i] == y)
- return false;
-
- if(table[i]+i == x+y)
- return false;
-
- if(table[i]-i == y-x)
- return false;
- }
- return true;
- }
- void dfs(int col, int n)
- {
- if(col == n)
- {
- count++;
- return;
- }
- for(int i = 0; i<n; i++)
- {
- if(check(col, i))
- {
- table[col] = i;
- dfs(col+1, n);
- //table[col] = 0;
- }
- }
- }
- int main(){
- int n;
- cin >> n;
- dfs(0, n);
- cout << count << endl;
- return 0;
- }
复制代码 |
|