Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
注意行和列一定要是局部变量,要不是无法还原,附AC代码(C语言)#include <stdio.h> #include <stdlib.h> #include <string.h> int n,k,i,j,l[10]; long cnt=0; char grids[10][10]; void dfs(int a,int b) { int i0,j0; if (b==0) { cnt++; return; } for (j0=a+1;j0<=n-1;j0++) for (i0=0;i0<=n-1;i0++) if (l[i0]&&grids[j0][i0]=='#') { l[i0]=0; b--; dfs(j0,b); b++; l[i0]=1; } } int main() { char u; do{ cnt=0; scanf("%d%d",&n,&k); if (n==-1&&k==-1) break; scanf("%c",&u); memset(l,1,sizeof(l)); for (i=0;i<=n-1;i++) for (j=0;j<=n;j++) scanf("%c",&grids[i][j]); dfs(-1,k); printf("%d\n",cnt); }while(1); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator