标签:dfspan idtransmarksp span idtransmarkspan
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 28790 | Accepted: 14255 |
Description
Input
Output
Sample Input
2 1 #. .# 4 4 ...# ..#. .#.. #... -1 -1
Sample Output
2 1
Source
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<map> #define INF 0x3f3f3f3f using namespace std; char a[10][10]; int hang[10],lie[10];//行标记,列标记 int n,m,lx,ly,num; int DFS(int x,int y,int ans) { if(ans==m) { num++; return 0; } for(int i=x; i<n; i++) //从x行开始遍历 { if(hang[i]) continue; for(int j=0; j<n; j++) { if(lie[j]) continue; if(a[i][j]=='#') { hang[i]=1; lie[j]=1; DFS(i,j,ans+1); lie[j]=0; hang[i]=0; } } } } int main() { while(~scanf("%d%d",&n,&m)) { if(n==-1&&m==-1) break; int flag=1; memset(hang,0,sizeof(hang)); memset(lie,0,sizeof(lie)); for(int i=0; i<n; i++) { scanf("%s",a[i]); } num=0; DFS(0,0,0); printf("%d\n",num); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:dfspan idtransmarksp span idtransmarkspan
原文地址:http://blog.csdn.net/became_a_wolf/article/details/47983321