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 29941223lw at 2007-01-29 15:16:25 on Problem 1011
#include<iostream>
using namespace std;

int sum=0,n,a[64];

int dfs(int no,int ma)
{int i;
	if(sum%ma==0) return ma;
for(i=no;i<n-1;i++)
dfs(no+1,ma+a[no]);
}

main()
{int i,j,max,c;
while(1)
{cin>>n;
if(n==0)
break;
for(i=0;i<n;i++)
{cin>>a[i];
sum+=a[i];
}
for(i=0;i<n-1;i++)
    for(j=0;j<n-i-1;j++)
		if(a[j]>a[j+1])
		{   c=a[j];
		    a[j]=a[j+1];
			a[j+1]=c;
		}
max=a[n-1];
max=dfs(0,max);
cout<<max<<endl;
}
}

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