# 1.5.4 Checker Challenge跳棋的挑战

1.5.4 Checker Challenge跳棋的挑战

```0   1   2   3   4   5   6
-------------------------
1 |   | O |   |   |   |   |
-------------------------
2 |   |   |   | O |   |   |
-------------------------
3 |   |   |   |   |   | O |
-------------------------
4 | O |   |   |   |   |   |
-------------------------
5 |   |   | O |   |   |   |
-------------------------
6 |   |   |   |   | O |   |
-------------------------
```

``6``

``````2 4 6 1 3 5
3 6 2 5 1 4
4 1 5 2 6 3
4``````

``````/*
ID:zhaofuk1
PROG: checker
LANG: C
*/
#include<stdio.h>
#include<string.h>
int n, tot = 0;
int digit[20], vis[3][50];
void dfs(int cur)
{
int i, j;
if(cur == n){
tot++;
if(tot < 4){
for(i = 0; i < n; i++){
if(i != 0)
printf(" ");
printf("%d", digit[i] + 1);
}
printf("\n");
}
}else for(i = 0; i < n; i++){
if(!vis[0][i] && !vis[1][cur + i] && !vis[2][cur + n - i]){
digit[cur] = i;
vis[0][i] = vis[1][cur + i] = vis[2][cur + n - i] = 1;
dfs(cur + 1);
vis[0][i] = vis[1][cur + i] = vis[2][cur + n - i] = 0;
}
}

}

int main()
{
int i, j, k;
//freopen("checker.in", "r", stdin);
//freopen("checker.out", "w", stdout);
scanf("%d", &n);
memset(vis, 0, sizeof(vis));
dfs(0);
printf("%d\n", tot);
return 0;
}
``````

``````/*
ID:zhaofuk1
PROG: checker
LANG: C
*/
#include<stdio.h>
#include<string.h>
int n, tot = 0;
int digit[20], vis[3][50];
void dfs(int cur)
{
int i, j;
if(cur == n){
tot++;
if(tot < 4){
for(i = 0; i < n; i++){
if(i != 0)
printf(" ");
printf("%d", digit[i] + 1);
}
printf("\n");
}
}else for(i = 0; i < n; i++){
if(!vis[0][i] && !vis[1][cur + i] && !vis[2][cur + n - i]){
digit[cur] = i;
vis[0][i] = vis[1][cur + i] = vis[2][cur + n - i] = 1;
dfs(cur + 1);
vis[0][i] = vis[1][cur + i] = vis[2][cur + n - i] = 0;
}
}

}

int main()
{
int i, j, k;
//freopen("checker.in", "r", stdin);
//freopen("checker.out", "w", stdout);
scanf("%d", &n);
memset(vis, 0, sizeof(vis));
dfs(0);
printf("%d\n", tot);
return 0;
}
``````