RK,fence8以及所谓心情
很犹豫应该用什么分类∼
貌似有点应该用oi吧,但是∼
上个周末整理了usaco,结果真的fence rails(著名搜索剪枝题)的fence8.pas彻底找不到∼
发给RK,他很囧的因为我的注册信息没用真名就不理我了∼于是我只得重新把还找得到的半成品程序粘贴一下搞ac它。。。
终于今天中午重新ac了。
所以下午心情好一点。
在电教楼占据制高点∼∼∼门外是许多人在看舞蹈队的舞台剧。我们这里双头能看,还有后面的模型制作∼
据说坐在我后面两个人都分别让我去看这两个,于是就∼
现在这里还是比较吵。
旁边在帝国∼
完。
(明天是记忆力的决赛∼)
{
TASK: fence8
LANG: PASCAL
ID: phoeagon
}
{A+,B-,D-,E-,F-,G+,I-,L-,N+,O-,P+,Q-,R-,S-,T-,V-,X+,Y-}
{ M 65520,0,655360}
type
arr=array[0..60]of longint;
var
i,waste:longint;
bds,rr:Arr;
n,r,ub:longint;
max:longint;
rail,sum:array[0..1024]of longint;
procedure qsrt(const l,r:longint);//inline;
var
i,j,x,y:longint;
begin
i:=random(r-l)+l;
x:=rail[i];
i:=l;j:=r;
repeat
while rail[i]<x do
inc(i);
while rail[j]>x do
dec(j);
if not(i>j)then
begin
y:=rail[i];
rail[i]:=rail[j];
rail[j]:=y;
inc(i);
dec(j);
end;
until i>=j;
if i<r then
qsrt(i,r);
if j>l then
qsrt(l,j);
end;
procedure init;//inline;
var
i,j,k,x:longint;
begin
read(n);
for i:=1 to n do begin
read(bds[i]);
inc(bds[0],bds[i]);
//sum[i]:=sum[i-1]+bds[i];
end;
read(r);
for i:=1 to r do
read(rail[i]);
qsrt(1,R);
for i:=1 to n-1 do
begin
k:=i;
for j:=i+1 to n do
if bds[j]<bds[k]then
k:=j;
x:=bds[k];bds[k]:=bds[i];bds[i]:=x;
end;
x:=0;
for i:=1 to r do
begin
sum[i]:=sum[i-1]+rail[i];
x:=x+rail[i];
if x<=bds[0]then
ub:=i
else break;
end; //writeln('**',ub);
end;
function search(const a,lst,{remain,}get:longint):boolean;//inline;
var
i,j{,x}:longint;
ch,ans:boolean;
begin ans:=false;
//if get>max then max:=get; //writeln(max);
if a=0 then exit(true);
//if get+(remain-waste)div rail[1]<max then
if waste+sum[a]>bds[0]then
exit(false);
if rail[a]=rail[a+1] then
begin
for i:=lst to n do
if rail[a]<=rr[i]then
begin
dec(rr[i],rail[a]);
if rr[i]<rail[a]then
begin ch:=true;{x:=rr[i];rr[i]:=0;}inc(waste,rr[i]);end
else ch:=false;
ans:=ans or search(a-1,i,{remain-rail[a],}get+1);
if ch then dec(waste,rr[i]);
inc(rr[i],rail[a]);
if ans then exit(ans);
end
end
else for i:=1 to n do
if rail[a]<=rr[i]then
begin
dec(rr[i],rail[a]);
if rr[i]<rail[a]then
begin ch:=true;{x:=rr[i];rr[i]:=0;}inc(waste,rr[i]);end
else ch:=false;
ans:=ans or search(a-1,i,{remain-rail[a],}get+1);
if ch then dec(waste,rr[i]);
inc(rr[i],rail[a]);
if ans then exit(ans);
end;
exit(ans);
end;
function work(const maxdep:longint):boolean;//inline;
begin
waste:=0;
rr:=bds;
exit(search(maxdep,1,{bds[0],}0));
end;
procedure w;
var
omax,i,l,u,ans,m:longint;
begin ans:=0;
{for i:=1 to r do
begin
omax:=max;
work(i);
if omax=max then break;
write(i,' ');
end;}
//rail[ub+1]:=maxlongint;
l:=1;u:=ub;
while l<=u do
begin
m:=(l+u)div 2;//write(m,' ');
if work(m)then
begin ans:=m;l:=m+1;end
else u:=m-1;
end;
writeln(ans);
end;
begin
//assign(input,'fence8.in');reset(input);
//assign(output,'fence8.out');rewrite(output);
init;
w;
close(input);close(output);
end.
|