Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:顶一下别沉了

Posted by xiaxia123 at 2006-11-04 12:50:14
In Reply To:哪位大牛讲一下 DFS的非递归实现,我这里有个代码看不太懂,似乎这个代码没用到堆栈 Posted by:xiaxia123 at 2006-11-04 12:40:40
> #include<stdio.h>
> int n,g[31][31];
> struct no
> {
> 	int f;
> 	int k;
> }node[31];
> void init()
> {
> 	int i,j;
> 	scanf("%d",&n);
> 	
> 	for(i=1;i<=n;i++)
> 		for(j=1;j<=n;j++)
> 			scanf("%d",&g[i][j]);
> 		return;
> }
> void DFS()
> {
> 	int i,v,u;
> 	for(i=1;i<=n;i++)
> 	{node[i].f=0,node[i].k=0;}
> 	i=0;v=1;
> 	do
> 	{
> 		do
> 		{
> 			i++;node[v].k=i;
> 			do
> 			{
> 				u=1;
> 				while(u<=n&&g[v][u]<=0)
> 					u++;
> 				g[v][u]=-1;g[u][v]=-1;
> 			}while(u==n+1||node[u].k==0);
> 			if(u!=n+1)
> 			{
> 				printf("%d----%d\n",v,u);
> 				node[u].f=v;v=u;
> 			}
> 		}while(u==n+1);
> 		if(node[v].k!=1) v=node[v].f;
> 	}while(node[v].k==1);
> 	return;
> }
> int main()
> {
> 	init();
> 	DFS();
> 	return 0;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator