| ||||||||||
| 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 | |||||||||
1A~~就是有点慢……157ms……希望大家指点……
发个甲骨文……
program asdf;
type
arr=record
d,l,c:longint;
end;
var
sum,n,m,ansl:longint;
d:array[0..20000] of arr;
ff:array[0..20000] of boolean;
first,next:array[0..20000] of longint;
procedure init;
var
i,s,e,l,t:longint;
begin
readln(sum);
readln(n);
readln(m);
fillchar(d,sizeof(d),0);
fillchar(first,sizeof(first),0);
fillchar(next,sizeof(next),0);
for i:=1 to m do
begin
readln(s,e,l,t);
if t>sum then
continue;
next[i]:=first[s];
d[i].d:=e;
d[i].l:=l;
d[i].c:=t;
first[s]:=i;
end;
end;
procedure sss(x,len,co:longint);
var
y,i,l,c:longint;
begin
if len>ansl then
exit;
if co>sum then
exit;
if x=n then
begin
if len<ansl then
ansl:=len;
exit;
end;
i:=first[x];
while i<>0 do
begin
y:=d[i].d;
l:=d[i].l;
c:=d[i].c;
if (c+co>sum)or(ff[y]) then
begin
i:=next[i];
continue;
end;
ff[y]:=true;
sss(y,len+l,co+c);
ff[y]:=false;
i:=next[i];
end;
end;
procedure main;
begin
fillchar(ff,sizeof(ff),0);
ff[1]:=true;
ansl:=maxlongint;
sss(1,0,0);
if ansl<100000 then
writeln(ansl)
else writeln('-1');
end;
begin
init;
main;
end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator