深度优先搜索dfs

//深度优先搜索dfs:
//INIT type map[maxn][maxn]; bool vst[maxn][maxn];  
//MODIFIED:const int maxn=100; 

void dfs(int r,int k)  {  
    int i;  
    if(...){    //到达终点
	....    //处理
	return;
    }  
    for(i... ){  //逐个遍历子节点    
        if(!vst[i] && ...){  
            vst[i]=1;  
            dfs(...); //将子节点作为父节点深搜  
            vst[i]=0;  
        }  
    }  
    dfs(r+1,k);  //特殊的可能跳过子节点的情况
}  

  

posted on 2013-08-13 21:31  Amyc  阅读(188)  评论(0编辑  收藏  举报