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:老是RE,实在找不出哪儿错了,望大牛赐教,谢谢。(我用的深搜)

Posted by 46590208 at 2007-03-27 00:32:03 on Problem 1847
In Reply To:老是RE,实在找不出哪儿错了,望大牛赐教,谢谢。(我用的深搜) Posted by:46590208 at 2007-03-27 00:21:31
> #include<stdio.h>
> const int MAXINT=100000000;
> int a[1002][1002];
> int search(int ,int);
> int N;
> int A,B;
> int main()
> {
> 	int i,j;		
> 	int length;
> 	freopen("t.txt","r",stdin);
> 	scanf("%d %d %d",&N,&A,&B);
> 	for(i=1;i<=N;i++)
> 	{
> 		scanf("%d",&a[i][0]);
> 		for(j=1;j<=a[i][0];j++)
> 			scanf("%d",&a[i][j]);
> 	}
> 	length=search(A,B);
> 	printf("%d",length);
> 	return 0;
> }
> 
> 
> int search(int i,int j)
> {
> 	int m,x,y;
> 	int min,p;
> 	if(a[i][1]==j)
> 		return 0;
> 	else
> 	{
> 		min=MAXINT;
> 		for(m=2;m<=a[i][0];m++)
> 		{
> 			if(a[i][m]==j)
> 				min=1;
> 		}
> 		for(p=1;p<=N;p++)
> 		{
> 			if(p!=i&&p!=j)
> 			{
> 				x=search(i,p);
> 				y=search(p,j);
> 				if(x!=-1&&y!=-1)
> 					if(x+y<min)
> 						min=x+y;
> 			}
> 		}
> 		if(min!=MAXINT)
> 			return min;
> 		else
> 			return -1;
> 	}
> }
> 

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