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

哪位大哥,大姐帮忙看一下 不知道在哪里错了

Posted by yegaofei at 2007-07-31 17:21:11 on Problem 3268
#include "stdio.h"
#include "string.h"
#include "iostream.h"
#define Max 100000000
int cost[1001],succ[1001],C[1001][1001],tag[1001][1001],n;
int f(int j,int k) 
{ 
    if(cost[j]==0)
	{
	   if(j==k) cost[j]=0;
	   else
	   {
	     int min=Max,i,i0=0;
		 for(i=1;i<=n;i++)
			 if(C[j][i]<Max&&tag[i][j]!=1)
			 {	 
				tag[i][j]=1;
				int x=f(i,k);
				if((x+C[j][i])<min)
				{
					min=x+C[j][i];
					i0=i;
				} 
			 }
		  memset(tag,0,sizeof(tag));
		  cost[j]=min;succ[j]=i0;
	   }
	}
	
	return cost[j];
}
int main()
{
  int i,j,p,m,k;
  cin>>n>>m>>k;
  for(i=1;i<=n;i++)
  {cost[i]=0;}
  for(i=1;i<=n;i++)
	  for(j=1;j<=n;j++)
	  {
		  C[i][j]=Max;
	  }
  for(int t=1;t<=m;t++)
  { 
	  scanf("%d%d%d",&i,&j,&p);
	  C[i][j]=p;
  }
  int max=-Max;
  for(i=1;i<=n;i++)
  {   
	 if(i!=k){
	  int s=f(i,k);
	  memset(tag,0,sizeof(tag));
	  memset(cost,0,sizeof(cost));
	  int t=f(k,i);
	  memset(tag,0,sizeof(tag));
	  memset(cost,0,sizeof(cost));
	  if(max<s+t&&s!=Max&&t!=Max) max=s+t;
	 }
  }
  if(-Max==max) printf("0\n");
  else if(max<Max) printf("%d\n",max);
  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