比赛 |
20111108 |
评测结果 |
AAAAAAAAAA |
题目名称 |
机房 |
最终得分 |
100 |
用户昵称 |
wk_noi |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-11-08 11:22:31 |
显示代码纯文本
Program orz;
Const
maxn=2501;
Var
n,m,i,j,c:longint;
d:array[1..maxn] of integer;
e:array[0..maxn,0..1] of integer;
f:array[0..maxn] of integer;
Function min(i,j:longint):longint;
begin
if i<j then
exit(i);
exit(j);
end;
Function check(i,j:longint):boolean;
begin
if e[i,0]-e[j-1,0]=0 then
exit(true);
if e[i,1]-e[j-1,1]=0 then
exit(true);
if abs(abs(e[i,0]-e[j-1,0])-abs(e[i,1]-e[j-1,1]))<=c then
exit(true);
exit(false);
end;
Begin
assign(input,'orz.in');
assign(output,'orz.out');
reset(input);
rewrite(output);
readln(n,c);
for i:=1 to n do
begin
readln(d[i]);
if d[i]=1 then
begin
e[i,0]:=e[i-1,0]+1;
e[i,1]:=e[i-1,1];
end
else
begin
e[i,1]:=e[i-1,1]+1;
e[i,0]:=e[i-1,0];
end;
end;
fillchar(f,sizeof(f),$7f);
f[1]:=1;
f[0]:=0;
for i:=2 to n do
for j:=1 to i-1 do
begin
if check(i,j) then
f[i]:=min(f[i],f[j-1]+1);
end;
writeln(f[n]);
close(input);
close(output);
End.