记录编号 |
32888 |
评测结果 |
AAAAAAAAAA |
题目名称 |
机房 |
最终得分 |
100 |
用户昵称 |
Des. |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.759 s |
提交时间 |
2011-11-08 19:31:46 |
内存使用 |
24.01 MiB |
显示代码纯文本
program orz;
var a,b,c:array[0..2501]of longint;
f:array[1..2501,1..2501]of longint;
t,k,m,n,i,j:longint;
function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end;
begin
assign(input,'orz.in');
reset(input);
assign(output,'orz.out');
rewrite(output);
readln(n,m);
for t:=1 to n do
begin
readln(c[t]);
if c[t]=2 then
begin
b[t]:=b[t-1]+1;
a[t]:=a[t-1];
end;
if c[t]=1 then
begin
b[t]:=b[t-1];
a[t]:=a[t-1]+1;
end;
end;
for i:=1 to n do
for j:=1 to n do
f[i,j]:=maxint;
for i:=1 to n do
for j:=i to n do
if (abs((a[j]-a[i-1])-(b[j]-b[i-1]))<=m)or(a[j]-a[i-1]=j-i+1)
or(a[j]-a[i-1]=0)then f[i,j]:=1;
for i:=1 to 1 do
for j:=i+1 to n do
for k:=i+1 to j do
f[i,j]:=min(f[i,j],f[i,k-1]+f[k,j]);
writeln(f[1,n]);
close(output);
end.