比赛 10101115 评测结果 AAATTTTTTT
题目名称 技能树 最终得分 30
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-15 09:38:21
显示代码纯文本
var
  n,p,i,j,max,nn:longint;
  a,ru:array[0..60,0..60]of longint;
  f:array[0..60,0..60]of boolean;

procedure go(k,m:longint);
var
  i,j:longint;
begin
  if (k>nn)or(k>p) then
  begin
    if m>max then max:=m;
    exit;
  end;
  for i:=n downto 1 do
   for j:=1 to i do
   if (ru[i,j]=0)and(not f[i,j]) then
   begin

     f[i,j]:=true;
     dec(ru[i-1,j-1]);
     dec(ru[i-1,j]);

     go(k+1,m+a[i,j]);

     f[i,j]:=false;
     inc(ru[i-1,j-1]);
     inc(ru[i-1,j]);

   end;
end;

begin
  assign(input,'skill.in'); reset(input);
  assign(output,'skill.out'); rewrite(output);
  readln(n,p);
  for i:=n downto 1 do
   for j:=1 to i do
    read(a[i,j]);
  for i:=n-1 downto 1 do
   for j:=1 to i do
   ru[i,j]:=2;
  nn:=((1+n)*n) div 2;
  max:=-maxlongint;
  go(1,0);
  writeln(max);
  close(input);
  close(output);
end.