Figure: The House of Santa Claus
Well, a couple of years later, like now, you have to ``draw‘‘ the house again but on the computer. As one possibility is not enough, we require all the possibilities when starting in the lower left corner. Follow the example in Figure 2 while defining your stretch.
Figure: This Sequence would give the Outputline 153125432
All the possibilities have to be listed in the outputfile by increasing order, meaning that 1234... is listed before 1235... .
So, an outputfile could look like this:
12435123 13245123 ... 15123421
题意: 一笔画问题。从1开始画,输出所有可能的情况
题解: DFS 只要用个数组 path保存下路径就可以了~~
AC代码:
#include<iostream> using namespace std; bool edge[6][6]={0},visit[6][6]; int path[10]; void dfs(int pos,int step){ if(step==8){ for(int i=0;i<9;i++) cout<<path[i]; cout<<endl; return ; } for(int i=1;i<6;i++){ if(edge[pos][i]&&visit[pos][i]){ visit[pos][i]=false; visit[i][pos]=false; path[step+1]=i; dfs(i,step+1); visit[pos][i]=true; visit[i][pos]=true; } } } int main(){ edge[1][2]=true;edge[1][5]=true;edge[1][3]=true; edge[2][1]=true;edge[2][5]=true;edge[2][3]=true; edge[3][2]=true;edge[3][5]=true;edge[3][4]=true; edge[3][1]=true; edge[4][3]=true;edge[4][5]=true;edge[5][3]=true; edge[5][4]=true;edge[5][1]=true;edge[5][2]=true; for(int i=0;i<6;i++) for(int j=0;j<6;j++) visit[i][j]=edge[i][j]; path[0]=1; dfs(1,0); return 0; }
291 - The House Of Santa Claus,布布扣,bubuko.com
291 - The House Of Santa Claus
原文地址:http://blog.csdn.net/mummyding/article/details/38517413