标签:void else 描述 tchar str 区别 pac get pre
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 53150 | Accepted: 25686 |
Description
Input
Output
Sample Input
2 1 #. .# 4 4 ...# ..#. .#.. #... -1 -1
Sample Output
2 1
一道基础的dfs题目
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; char mapp[10][10]; int sum=0; int n,k; void dfs(int x,int y,int vis1[10],int vis2[10],int s){ s++; if(s==k) sum++; else{ for(int i=x;i<n;i++){ for(int j=0;j<n;j++){ if(vis1[i]==0&&vis2[j]==0&&mapp[i][j]==‘#‘){ printf("%d %d %d\n",s+1,i,j); vis1[i]=1;vis2[j]=1; dfs(i,j,vis1,vis2,s); vis1[i]=0;vis2[j]=0; } } } } } int main(){ int vis1[10]={0},vis2[10]={0}; while(~scanf("%d%d",&n,&k)){ if(n==-1&&k==-1) break; getchar(); memset(vis1,0,sizeof(vis1)); memset(vis2,0,sizeof(vis2)); sum=0; for(int i=0;i<n;i++){ gets(mapp[i]); } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(mapp[i][j]==‘#‘){ vis1[i]=1;vis2[j]=1; dfs(i,j,vis1,vis2,0); vis1[i]=0;vis2[j]=0; } } } printf("%d\n",sum); } return 0; }
标签:void else 描述 tchar str 区别 pac get pre
原文地址:http://www.cnblogs.com/monocolor/p/7988860.html