Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
超时了,大牛们帮忙看下怎么改进啊!!!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator