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

郁闷了,按照题解来写,还是TLE了

Posted by Exile_oi at 2006-07-11 15:05:20 on Problem 1011
#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:
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