讨论 / 一次AC,好久没有了~~,最裸的程序不加优化~~
noipyubin 2011-10-10 21:07:00
点我顶贴 收藏 删除
var

i,j,k,s,m,n,t1,t,t2,min:longint;

a:array[1..1000,1..2] of longint;

f:array[0..1000,1..16,1..16,1..16] of longint;

b1,b2,b3:array[1..16,1..16] of longint;

procedure init;

begin

readln(n);

for i:=1 to n do

readln(a[i,1],a[i,2]);

for i:=1 to 16 do

begin

for j:=1 to 16 do

read(b1[i,j]);

readln;

end;

for i:=1 to 16 do

begin

for j:=1 to 16 do

read(b2[i,j]);

readln;

end;

for i:=1 to 16 do

begin

for j:=1 to 16 do

read(b3[i,j]);

readln;

end;

end;

procedure kp(x,y:longint);

var

i,j,k,k1:longint;

begin

i:=x;j:=y;k:=a[(x+y)div 2,1];

while i<j do

begin

while a[i,1]<k do inc(i);

while a[j,1]>k do dec(j);

if i<=j then

begin

k1:=a[i,1];

a[i,1]:=a[j,1];

a[j,1]:=k1;

k1:=a[i,2];

a[i,2]:=a[j,2];

a[j,2]:=k1;

inc(i);

dec(j);

end;

end;

if i<y then kp(i,y);

if x<j then kp(x,j);

end;

procedure pp1;

var

i,j,k,x,y,z:longint;

begin;

kp(1,n);

f[0,1,1,1]:=0;

min:=999999999;

for i:=1 to n do

begin

for x:=1 to 16 do

for y:=1 to 16 do

for z:=1 to 16 do

begin

if f[i,a[i,2],y,z]>f[i-1,x,y,z]+b1[x,a[i,2]] then

f[i,a[i,2],y,z]:=f[i-1,x,y,z]+b1[x,a[i,2]];

if i=n then

if min>f[i,a[i,2],y,z] then

min:=f[i,a[i,2],y,z];

end;

for x:=1 to 16 do

for y:=1 to 16 do

for z:=1 to 16 do

begin

if f[i,x,a[i,2],z]>f[i-1,x,y,z]+b2[y,a[i,2]] then

f[i,x,a[i,2],z]:=f[i-1,x,y,z]+b2[y,a[i,2]];

if i=n then

if min>f[i,x,a[i,2],z] then

min:=f[i,x,a[i,2],z];

end;

for x:=1 to 16 do

for y:=1 to 16 do

for z:=1 to 16 do

begin

if f[i,x,y,a[i,2]]>f[i-1,x,y,z]+b3[z,a[i,2]] then

f[i,x,y,a[i,2]]:=f[i-1,x,y,z]+b3[z,a[i,2]];

if i=n then

if min>f[i,x,y,a[i,2]] then

min:=f[i,x,y,a[i,2]];

end;

end;

end;

begin

assign(input,'644.in');

assign(output,'644.out');

reset(input);

rewrite(output);

readln(t);

for t1:=1 to t do

begin

fillchar(f,sizeof(f),127);

init;

pp1;

writeln(min);

end;

close(input);

close(output);

end.

#1 阮鹏博@2011-10-06 22:16:00
回复 删除
???

天神那 哪题那 猥琐那

#2 阮鹏博@2011-10-06 22:17:00
回复 删除
抢个sofa

sofa

#3 slzxqjh@2011-10-10 21:07:00
回复 删除
min:=999999999;

汗~~不过的确是个好方法。

查看更多回复
提交回复