Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 47960 | Accepted: 23210 |
Description
Input
Output
Sample Input
2 1 #. .# 4 4 ...# ..#. .#.. #... -1 -1
Sample Output
2 1
Source
#include<stdio.h> char a[10][10]; int row[10],col[10]; int n,m,c; void dfs(int x,int s) { int i,j; if(s==m){ c++; return; } for(i=x;i<n;i++){ for(j=0;j<n;j++){ if(a[i][j]==‘#‘&&row[i]==0&&col[j]==0){ a[i][j]=‘.‘; row[i]=1; col[j]=1; dfs(i,s+1); a[i][j]=‘#‘; row[i]=0; col[j]=0; } } } } int main() { int i; while(scanf("%d%d",&n,&m)&&!(n==-1&&m==-1)){ for(i=0;i<n;i++){ getchar(); scanf("%s",a[i]); } c=0; dfs(0,0); printf("%d\n",c); } return 0; }
原文:http://www.cnblogs.com/yzm10/p/7252634.html