这个。。本来是想试试LRJ的回溯法的。。不过这题真是有点奇怪啊。。。用回溯超时,然后就变成直接打表了。。。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n, cnt;
int vis[30][30];
/*
void Search(int cur)
{
int i;
if (cur == n)
cnt++;
else
{
for (i = 0; i < n; i++)
if (!vis[0][i] && !vis[1][cur + i] && !vis[2][cur - i + n])
{
vis[0][i] = vis[1][cur + i] = vis[2][cur - i + n] = 1;
Search(cur + 1);
vis[0][i] = vis[1][cur + i] = vis[2][cur - i + n] = 0;
}
}
}
int main()
{
//freopen("input.txt", "r", stdin);
while (scanf("%d", &n) && n)
{
memset(vis, 0, sizeof(vis));
cnt = 0;
Search(0);
printf("%d\n", cnt);
}
return 0;
}
*/
int main()
{
int num[10]={1,0,0,2,10,4,40,92,352,724};
int n;
while(scanf("%d",&n),n)
{
printf("%d\n",num[n-1]);
}
return 0;
}