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 clearriver at 2007-05-13 22:52:49
#include<iostream>
using namespace std;
#include<stdio.h>
void fs(int (*a)[101],int i,int *f,long &sum,int n);
void main()
{
	int n;
	int a[101][101];
	while(scanf("%d",&n)!=EOF)
	{
	int i,j;
	long sum=0,min;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			cin>>a[i][j];
		int *f=new int[n];
		for(j=0;j<n;j++)
			f[j]=0;
		fs(a,0,f,sum,n);
		min=sum;
		for(i=1;i<n;i++)
		{
			sum=0;
			for(j=0;j<n;j++)
				f[j]=0;
			fs(a,i,f,sum,n);
			if(min>sum)
				min=sum;
		}
		cout<<min<<endl;
	}
}
void fs(int (*a)[101],int i,int *f,long &sum,int n)
{
	f[i]=1;
	for(int j=0;j<n;j++)
	{
		if(f[j]==0)
		{
			sum+=a[i][j];
			fs(a,j,f,sum,n);
		}
	}
}

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