比赛 10101115 评测结果 AAAATTTTTT
题目名称 技能树 最终得分 40
用户昵称 ybh 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-15 11:30:53
显示代码纯文本
program skill;
var
  a:array[0..50,0..50] of longint;
  b:array[0..50,0..50] of boolean;
  n,m,i,j,max,sum:longint;

procedure dfs(i,j,m,w:longint);
var
  i1,j1:longint;
begin
  if w>max then max:=w;
  if m=0 then
  begin
    exit;
  end;
  if i>n then exit;
  if j<n-i+1 then
  begin
    i1:=i;
    j1:=j+1
  end
  else
  begin
    i1:=i+1;
    j1:=1;
  end;
  if (b[i-1,j] and b[i-1,j+1]) or (i=1) then
  begin
    b[i,j]:=true;
    dfs(i1,j1,m-1,w+a[i,j]);
    b[i,j]:=false;
  end;
  dfs(i1,j1,m,w);
end;

begin
  assign(input,'skill.in');
  reset(input);
  assign(output,'skill.out');
  rewrite(output);
  readln(n,m);
  sum:=0;
  for i:=1 to n do
    for j:=1 to n-i+1 do
    begin
      read(a[i,j]);
      sum:=sum+a[i,j];
    end;
  if m>=n*(n+1) div 2 then
  begin
    writeln(sum);
    close(input);
    close(output);
    halt;
  end;
  fillchar(b,sizeof(b),false);
  max:=0;
  dfs(1,1,m,0);
  writeln(max);
  close(input);
  close(output)
end.