比赛 20110414 评测结果 AATTTTTTTTTWTTT
题目名称 奶牛的跳格子游戏 最终得分 13
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-04-14 11:19:03
显示代码纯文本
var
  m,n,i:longint;
  a:Array[0..1000000]of longint;
  v:array[0..1000000]of boolean;
  max:int64;

procedure go(k,t:longint; s:int64);
var
  i:longint;
begin
  if (k=0)and(t=-1) then
  begin
    if s>max then max:=s;
    exit;
  end;
  if t=1 then
  begin
    for i:=1 to m do
    if k+i<=n then
    begin
      v[k+i]:=true;
      go(k+i,t,s+a[k+i]);
      v[k+i]:=false;
    end;
    go(k,-1,s);
  end
  else begin
    if (k=n)or(t=-1) then
    begin
      for i:=1 to m do
      if (not v[k-i])and(k>=i)and(v[k-i+1]) then
      begin
        v[k-i]:=true;
        go(k-i,-1,s+a[k-i]);
        v[k-i]:=false;
      end;
    end;
  end;
end;

begin
  assign(input,'hop.in'); reset(input);
  assign(output,'hop.out'); rewrite(output);
  readln(n,m);
  for i:=1 to n do read(a[i]);
  max:=-maxlongint;
  go(0,1,0);
  writeln(max);
  close(input);
  close(output);
end.