比赛 20111108 评测结果 AAAAAAAAAA
题目名称 机房 最终得分 100
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-11-08 09:53:14
显示代码纯文本
var
  i,j,n,m:longint;
  f,s,a:array[0..100000]of longint;

function min(x,y:longint):longint;
begin
  if x<y then exit(x);
  exit(y);
end;

function ok(x,y:longint):boolean;
var
  now,l:longint;
begin
  now:=s[y]-s[x-1];
  l:=y-x+1;
  if (now=l)or(now=0)or(abs(now-l+now)<=m) then exit(true);
  exit(false);
end;

begin
  assign(input,'orz.in'); reset(input);
  assign(output,'orz.out'); rewrite(output);
  readln(n,m);
  for i:=1 to n do
  begin
    readln(a[i]);
    dec(a[i]);
    s[i]:=s[i-1]+a[i];
  end;
  for i:=1 to n do
  begin
    f[i]:=maxlongint;
    for j:=1 to i do
    if (ok(j,i))and(f[j-1]+1<f[i]) then
    f[i]:=f[j-1]+1;
  end;
  writeln(f[n]);
  close(input);
  close(output);
end.