| ||||||||||
| 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 | |||||||||
我的样例能过,之前有人给的很多数据,都能过,但还是WA,麻烦各位高手帮帮忙program poj1011 ;
type aa=array[1..64]of integer;
var i,j,k,n,long:integer;
sm:aa;
find:boolean;
map:array[1..64]of integer;
b:array[1..64]of boolean;
procedure qsort(var a:aa;l,r:integer);
var i,j,t:integer;
begin
if l<r then
begin
t:=a[l];
i:=l;
j:=r;
repeat
while (i<j)and (t>=a[j]) do j:=j-1;
if i<j then
begin
a[i]:=a[j];
i:=i+1;
end;
while (i<j)and(t<=a[i]) do i:=i+1;
if i<j then
begin
a[j]:=a[i];
j:=j-1;
end;
until i>=j;
a[i]:=t;
qsort(a,l,i-1);
qsort(a,i+1,r);
end;
end;
procedure put(num,x:integer);
var i,j,k:integer;
begin
if find then exit;
if num=n then begin find:=true; exit;end
else
if map[x]=long then put(num,x+1)
else
if map[x]=0 then
begin
i:=2;
while b[i] do i:=i+1;
b[i]:=false;
map[x]:=map[x]+sm[i];
put(num+1,x);
map[x]:=map[x]-sm[i];
b[i]:=true;
end
else
begin
for i:=2 to n do
if ((map[x]+sm[i])<=long)and(b[i]) then
begin
map[x]:=map[x]+sm[i];
b[i]:=false;
put(num+1,x);
map[x]:=map[x]-sm[i];
b[i]:=true;
end;
end
end;
begin
readln(n);
while n<>0 do
begin
fillchar(sm,sizeof(sm),0);
k:=0;
for i:=1 to n do begin read(sm[i]); k:=k+sm[i];end;
readln;
qsort(sm,1,n);
find:=false;
long:=sm[1]-1;
while not find do
begin
long:=long+1;
if (k mod long)=0 then
begin
fillchar(b,sizeof(b),true);
fillchar(map,sizeof(map),0);
map[1]:=sm[1];
put(1,1);
end;
end;
writeln(long);
readln(n)
end
end.
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator