POJ 2488(dfs+字典序)

2015-07-20 17:37:48 · 作者: · 浏览: 5

poj2488

题意:

问能不能不重复地走能遍历所有的棋格,走法按中国象棋马的方法。

分析: dfs+字典序输出...

我的字典序处理是用的String 来存,每次dfs后将该次有效遍历的地址加到串里面。从(0,0)开始。其他的就是基本的dfs知识~



#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #define Max 30 using namespace std; int n,m; int temp; int vis[Max][Max]; int dir[8][2]={{-1,-2},{1,-2},{-2,-1},{2,-1},{-2,1},{2,1},{-1,2},{1,2}}; int dfs(int x,int y,int step,string tt) { if(step==temp) { cout<
       
        =0 && xx
        
         =0 && yy
         
          >t; int ans=1; while(t--) { scanf("%d%d",&n,&m); temp=n*m; memset(vis,0,sizeof(vis)); vis[0][0]=1; printf("Scenario #%d:\n",ans++); if(!dfs(0,0,1,"A1")) printf("impossible\n\n"); } return 0; }