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 |
郁闷了,按照题解来写,还是TLE了#include <cstdio> #include <algorithm> const int mn=64; bool u[mn]; int n,i,len,s,p[mn]; bool DFS(int d,int l,int b){ if(d==n) return 1; int i,j; for(i=b;i!=n;++i) if(u[i]){ u[i]=0; if((j=p[i]+l)<len){ if(DFS(d+1,j,i+1)) return 1; u[i]=1; if(b==0) break; } else if(j==len){ if(DFS(d+1,0,0)) return 1; u[i]=1; break; } else{ u[i]=1; break; } u[i]=1; } return 0; } int main(){ for(;;){ scanf("%d",&n); if(n==0) return 0; for(s=i=0;i!=n;++i){ scanf("%d",p+i); s+=p[i]; } std::sort(p,p+n); for(len=p[n-1];;++len) if(s%len==0){ memset(u,1,sizeof(u)); if(DFS(0,0,0)){ printf("%d\n",len); break; } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator