比赛 |
20101101 |
评测结果 |
AAAAATTTTT |
题目名称 |
奇怪的监狱 |
最终得分 |
50 |
用户昵称 |
reamb |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-01 20:50:56 |
显示代码纯文本
program prison;
var
p,q,i,k,d,j:longint;
hash:array[1..1000]of boolean;
biaozhi:array[1..1000,1..1000]of boolean;
function sf(x,y:longint):longint;
var
i:integer;
min,t:longint;
y1,y2:longint;
begin
min:=maxlongint;
t:=0;
for i:=x to y do
if hash[i] then
begin
y1:=0;
y2:=0;
if biaozhi[x,i-1] then
y1:=sf(x,i-1);
if biaozhi[i+1,y] then
y2:=sf(i+1,y);
t:=y1+y2+y-x;
if t<min then
min:=t
end;
sf:=min
end;
begin
assign (input,'prison.in');
reset (input);
assign (output,'prison.out');
rewrite (output);
readln (p,q);
fillchar(hash,sizeof(hash),false);
fillchar(biaozhi,sizeof(biaozhi),false);
for i:=1 to q do
begin
read (d);
hash[d]:=true;
biaozhi[d,d]:=true
end;
for i:=1 to p-1 do
for j:=i+1 to p do
if hash[j] then
biaozhi[i,j]:=true
else
biaozhi[i,j]:=biaozhi[i,j-1];
k:=sf(1,p);
writeln (k);
close (input);
close (output)
end.