比赛 |
20120706 |
评测结果 |
AWWWWTTTTW |
题目名称 |
排队 |
最终得分 |
10 |
用户昵称 |
czp |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2012-07-06 11:45:27 |
显示代码纯文本
var
a:array[0..1000,0..1000] of longint;
h:array[0..1000] of longint;
o:array[0..1000] of boolean;
i,j,m,n,k,ans,u,last,ct:longint;
procedure dfs(v,t:longint);
var i,j,l:longint;
begin
inc(ct);
if ct>1000000 then exit;
if ans>last then exit;
if v=n then begin if ans<last then last:=ans; exit; end;
l:=random(n)+1;
for j:=l to l+n-1 do
begin
i:=j mod n;if i=0 then i:=n;
if (not o[i]) and(h[t]-h[i]<=k) then
begin
o[i]:=true;
ans:=ans+a[t,i];
dfs(v+1,i);
ans:=ans-a[t,i];
o[i]:=false;
end;
end;
end;
begin
assign(input,'queuea.in');reset(input);
assign(output,'queuea.out');rewrite(output);
readln(n,k);
randomize;
u:=0; h[0]:=maxlongint;
for i:=1 to n do begin read(h[i]);if h[i]<h[u] then u:=i; end;
for i:=1 to n do
begin
for j:=1 to n do
read(a[i,j]);
readln;
end;
last:=maxlongint;
o[u]:=true;
dfs(1,u);
writeln(last);
close(input);close(output);
end.