Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 28461 | Accepted: 14076 |
Description
Input
Output
Sample Input
2 1 #. .# 4 4 ...# ..#. .#.. #... -1 -1
Sample Output
2 1
Source
TLE 4次 没赶上交的时间
AC代码:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; char map[8][8],s[8]; int isuse[8]; int cns,n,k; void dfs(int put,int dx){ if(put==k){cns++;return;} for(int i=dx;i<n;++i) for(int j=0;j<n;++j){ if(isuse[j]==1)continue; if(map[i][j]=='.')continue; isuse[j]=1; dfs(put+1,i+1); isuse[j]=0; } return; } int main(){ int i,j; while(cin>>n>>k&&(n!=-1||k!=-1)){ memset(isuse,0,sizeof(isuse)); for(i=0;i<n;i++){ scanf("%s",s); for(j=0;j<n;j++){ map[i][j]=s[j]; } } cns=0; dfs(0,0); cout<<cns<<'\12'; } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/zp___waj/article/details/47360191