- 贪吃的九头龙
- 2009-09-19 13:12:00 @
const
none=maxint*10000;
type
integer=longint;
var
n,m,k,i,j,ans:integer;
f:array[0..350,-1..350,0..1]of integer;
b:array[0..350,0..350]of integer;
a:array[1..350,0..350]of integer;
v:array[0..350]of boolean;
g:array[1..350]of integer;
d:array[0..1,0..1]of integer;
function min(a,b:integer):integer;
begin
if a>b then exit(b) else exit(a)
end;
procedure init;
var
i,j,p,q,r:integer;
begin
read(n,m,k);
for i:=1 to n-1 do
begin
read(p,q,r);
b[p,q]:=r;
b[q,p]:=r;
end;
end;
procedure dfs(u,ba:integer);
var
i,j:integer;
begin
v:=true;
for i:=1 to n do
if b0 then
if v[i]=false then
begin
inc(a[0]);
a[u,a[0]]:=i;
g[i]:=a[0];
dfs(i,ba);
end;
v:=false;
end;
procedure doo(u,fa:integer);
var
i,j,x,y,t:integer;
q:boolean;
p:integer;
begin
v:=true;
for i:=1 to a[0] do
begin
x:=a[i];
doo(x,u);
end;
if fa=0 then
p:=min(f[x][j][1]+f[y,i-j-1,t]+d[t,1]*b,p);
f[i][t]:=min(f[i][t],p);
end;
end;
end;
begin
init;
if m=2 then d[0][0]:=1 else d[0][0]:=0;
d[1][1]:=1;
if n>=k+m-1 then
begin
v[0]:=true;
dfs(1,0);
for j:=0 to n do begin f[0][j][1]:=none; f[0][j][0]:=none; end;
for i:=0 to n do begin f[i][-1][1]:=none; f[i][-1][0]:=none; end;
f[0][0][1]:=0; f[0][0][0]:=0;
ans:=none;
doo(1,0);
write(f[a[1][a[1][0]],k-1,1]);
end
else write('-1');
end.
最后两个点到底是哪错了,一个晚上啊!!!