- 注册时间
- 2005-5-29
- 最后登录
- 1970-1-1
|
发表于 2006-5-9 22:25:00
|
显示全部楼层
- #include <stdio.h>
- #include <string.h>
- int cnt;
- int n,k;
- char d[100];
- int canput(int pos)
- {
- int x,y,i;
- x=pos%n;
- y=pos/n;
- for (i=0;i<x;i++) if (d[y*n+i]==1) return 0;
- for (i=0;i<y;i++) if (d[i*n+x]==1) return 0;
- return 1;
- }
- void exe(int pos,int count)
- {
- if (count==k) {cnt++;return;}
- if (pos==n*n) return;
- if (canput(pos))
- {
- d[pos]=1;
- exe(pos+1,count+1);
- d[pos]=0;
- exe(pos+1,count);
- }
- else exe(pos+1,count);
- return;
- }
- int main()
- {
- while(scanf("%d%d",&n,&k)!=EOF)
- {
- cnt=0;
- memset(d,0,100);
- exe(0,0);
- printf("%d\n",cnt);
- }
- }
复制代码
简单得测试了几个数据。。。
不知道正不正确。
|
|