| ||||||||||
| 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 | |||||||||
PASCAL代码 1ACvar n,len,parts,max,sum,tail:longint;
l:array[0..64,0..2]of longint;
used:array[0..64]of boolean;
procedure sort;
var i,j:longint;
t,k:longint;
begin
for i:=1 to n do begin
for j:=i+1 to n do begin
if (l[i,0]<l[j,0]) then begin
t:=l[i,0];
l[i,0]:=l[j,0];
l[j,0]:=t;
end;
end;
end;
i:=0;
while i<n do begin
j:=i+1;
while (j<n)and(l[j,0]=l[i,0]) do inc(j);
for k:=i to j do l[k,1]:=j;
i:=j;
end;
end;
procedure init;
var i,j:longint;
sumr:longint;
begin
for i:=0 to n-1 do begin
used[i]:=false;
end;
sumr:=0;
i:=n-1;
for i:=n-1 downto 0 do begin
inc(sumr,l[i,0]);
if sumr>len then break;
end;
tail:=i;
end;
function sumres(m:longint):longint;
var sumr:longint;
i:longint;
begin
sumr:=0;
for i:=m to n do begin
if (used[i]=false) then inc(sumr,l[i,0]);
end;
exit(sumr);
end;
function search(res,next,cpl:longint):boolean;
var i:longint;
begin
if res=len then begin
res:=0;
next:=1;
inc(cpl);
end;
if cpl=parts then exit(true);
i:=next;
while i<n do begin
if used[i]=false then begin
if res+l[i,0]<=len then begin
used[i]:=true;
if search(res+l[i,0],i+1,cpl) then exit(true);
used[i]:=false;
if res=0 then break;
if res+l[i,0]=len then break;
end;
end;
inc(i);
end;
exit(false);
end;
var i:longint;
begin
readln(n);
while n<>0 do begin
sum:=0;
fillchar(l,sizeof(l),0);
for i:=0 to n-1 do begin
read(l[i,0]);
inc(sum,l[i,0]);
end;
sort;
max:=l[0,0];
for len:=max to sum do begin
if sum mod len=0 then begin
parts:=sum div len;
init;
if search(0,0,0) then begin
writeln(len);
break;
end;
end;
end;
readln(n);
if n=0 then halt;
end;
end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator