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 sky123 at 2007-04-24 13:34:10 on Problem 1011
\\Report    TIME OVER!!
            ~~~~~~~~~~
Type
 int=integer;
Var
 d:array[1..100]of int;
 n,sum,max,min,i,j:int;

Function Check(x:int):boolean;
 Var
  w:array[1..100]of int;
  m:int;
  y:boolean;
 Procedure Solve(k:int);
  Var
   i,j:int;
  Begin
   for i:=1 to m do
    if (d[k]+w[i]=x)or(d[k]+w[i]+min<=x)
     then begin
           w[i]:=w[i]+d[k];
           if k=n
            then begin
                  y:=true;
                  for j:=1 to m do
                   if w[j]<>x
                    then begin
                          y:=false;
                          break;
                         end;
                 end
            else Solve(k+1);
           if y
            then exit;
           w[i]:=w[i]-d[k];
          end;
  End;
 Begin
  if sum=x
   then exit(true);
  m:=sum div x;
  y:=false;
  fillchar(w,sizeof(w),0);
  Solve(1);
  exit(y);
 End;

BEGIN
 While True Do Begin
  readln(n);
  if n=0 then break;
  sum:=0; max:=0;
  for i:=1 to n do
   begin
    read(d[i]);
    sum:=sum+d[i];
   end;
  for i:=1 to n-1 do
   for j:=i+1 to n do
    if d[i]<d[j]
     then begin
           d[i]:=d[i] xor d[j];
           d[j]:=d[j] xor d[i];
           d[i]:=d[i] xor d[j];
          end;
  max:=d[1]; min:=d[n];
  for i:=max to sum do
   if sum mod i=0
    then if Check(i)
          then begin
                writeln(i);
                break;
               end;
 End;
END.


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