访问图书馆

来源:百度知道 编辑:UC知道 时间:2024/06/30 13:24:35
经过数月的精心准备,Peer Brelstet,一个出了名的盗画者,准备开始他的下一个行动。艺术馆的结构,每条走廊要么分叉为两条走廊,要么通向一个展览室。Peer知道每个展室里藏画的数量,并且他精确测量了通过每条走廊的时间。由于经验老到,他拿下一幅画需要5秒的时间。你的任务是编一个程序,计算在警察赶来前,他最多能偷到多少幅画。

输入
第1行是警察赶到的时间,以秒为单位。第2行描述了艺术馆的结构,是一串非负整数,成对地出现:每一对的第一个数是走过一条走廊的时间,第2个数是它末端的藏画数量:如果第2个数 是0那么说明这条走廊分叉为两条另外的走廊。数据按照深度优先的次序给出,请看样例。
一个展室最多有20幅画。通过每个走廊的时间不超过20秒。艺术馆最多有100个展室。警察赶到的时间在10分钟以内。

const maxn=1500;
type point=^node;
node=record
data:longint;
next:point;
end;
var a:array[1..maxn]of point;
s:array[1..maxn]of longint;
n,u:longint;
f:array[0..2,1..maxn]of longint;
procedure init;
var p:point;
i,j,m,t:longint;
begin
readln(n);
for i:=1 to n do
begin
read(t);
if i=1 then u:=t;
s[t]:=1;
read(m);
new(a[t]);
a[t]:=nil;
if m<>0 then for j:=1 to m do
begin
new(p);
read(p^.data);
p^.next:=a[t];
a[t]:=p;
end;
if m=0 then
begin
f[0,t]:=s[t];
f[1,t]:=0;
f[2,t]:=s[t];
end;
end;
close(input);
end;
function min(x,y:longint):longint;
begin
if x>y then min:=y else min:=x;
end;
procedure try(k:longint);
var p:point;
i,j,t:longint;
begin
if a[k]=nil then exit;
new(p);
p:=a[k];
t:=0;
f[1,k]:=0;
f[2,k]:=0;
while p&