标签:dfs
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 23091 | Accepted: 11457 |
Description
Input
Output
Sample Input
2 1 #. .# 4 4 ...# ..#. .#.. #... -1 -1
Sample Output
2 1
#include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <limits.h> #include <ctype.h> #include <string.h> #include <string> #include <math.h> #include <algorithm> #include <iostream> #include <queue> #include <stack> #include <deque> #include <vector> #include <set> //#include <map> using namespace std; #define MAXN 10 char map[MAXN][MAXN]; int col[MAXN]; int n,k; int ans; void DFS(int row,int sum){ if(sum == k){ ans++; return ; } if(row >= n){ return ; } int i; for(i=0;i<n;i++){ if(col[i]==0 && map[row][i]=='#'){ col[i] = 1; DFS(row+1,sum+1); col[i] = 0; } } DFS(row+1,sum); return ;//时间变快 } int main(){ int i,j; while(~scanf("%d%d",&n,&k)){ if(n==-1 && k==-1){ break; } for(i=0;i<n;i++){ scanf("%s",map[i]); } memset(col,0,sizeof(col)); ans = 0; DFS(0,0); printf("%d\n",ans); } return 0; }
标签:dfs
原文地址:http://blog.csdn.net/zcr_7/article/details/39735347