记录编号 48876 评测结果 AAAAAAAAAA
题目名称 奇怪的监狱 最终得分 100
用户昵称 Gravatardigital-T 是否通过 通过
代码语言 Pascal 运行时间 0.071 s
提交时间 2012-11-06 20:18:33 内存使用 7.79 MiB
显示代码纯文本
var
p,q,i,j,k,t,n,ans,h:longint;
f,g:array[1..1000,1..1000]of longint;
kk:array[1..1000]of boolean;
begin
assign(input,'prison.in');reset(input);
assign(output,'prison.out');rewrite(output);
read(p,q);
fillchar(kk,sizeof(kk),true);
for i:=1 to q do
 begin
  read(j);
  kk[j]:=false;
 end;

//_________________
for i:=1 to 1000 do
 for j:=1 to 1000 do if j=1 then f[i,j]:=0 else f[i,j]:=1000000;
//_________________
j:=1;
for i:=1 to p do
 if kk[i]then inc(f[j,1])else inc(j);
n:=j;
//g[,]_________________________
for i:=1 to n do
 for j:=i+1 to n do
  begin
   for k:=i to j do
    g[i,j]:=g[i,j]+f[k,1];
   g[i,j]:=g[i,j]+j-i-1;
  end;
{for i:=1 to n do
 for j:=i+1 to n do writeln(i,' ',j,' ',g[i,j]);
 writeln;  }
//_____________________________
for i:=1 to n-1 do begin f[i,2]:=f[i,1]+f[i+1,1];f[i,1]:=0;end;f[n,1]:=0;
for i:=3 to n do
 for j:=1 to n-i+1 do
   for k:=1 to i-1 do
    if f[j,i]>f[j,k]+f[j+k,i-k]+g[j,j+i-1] then
     f[j,i]:=f[j,k]+f[j+k,i-k]+g[j,j+i-1];

{for i:=1 to n do
  for j:=1 to n-i+1 do
   writeln(j,' ',i,' ',f[j,i]);  }

write(f[1,n]);

close(input);close(output);
end.