比赛 10101115 评测结果 AAAAWAWWWW
题目名称 技能树 最终得分 50
用户昵称 donny 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-15 11:25:42
显示代码纯文本
program skill;
const
  ceng:array[1..50]of longint=(1,3,6,10,15,21,28,36,45,55,66,78,91,105,120,
                               136,153,171,190,210,231,253,276,300,325,351,
                               378,406,435,465,496,528,561,595,630,666,703,
                               741,780,820,861,903,946,990,1035,1081,1128,
                               1176,1225,1275);
type
  sss=record
    wei,dian:longint;
  end;
var
  n,m:longint;
  q:array[1..50,0..50]of longint;
  a:array[1..50,1..50]of longint;
  f:array[1..50,1..50]of sss;
  i,j,k,l:longint;
  max:longint;
  r:real;
  s,t:longint;
procedure jian(const x,y:longint);
var
  i,j:longint;
begin
  for i:=x downto 1 do
    for j:=y to y+x-i do
      if a[i,j]=0 then dec(f[x,y].dian);
end;
procedure suan;
begin
  for i:=1 to n do
  begin
    q[i,0]:=0;
    for j:=1 to n-i+1 do
    begin
      f[i,j].dian:=ceng[i];
      f[i,j].wei:=0;
      q[i,j]:=q[i,j-1]+a[i,j];
    end;
  end;
  for i:=1 to n do
    for j:=1 to n-i+1 do
      for k:=i downto 1 do
        f[i,j].wei:=f[i,j].wei+q[k,j+i-k]-q[k,j-1];

  for i:=1 to n do
    for j:=1 to n-i+1 do
      jian(i,j);
end;
procedure delete(const x,y:longint);
begin
  a[x,y]:=0;
  if x<>1 then
  begin
    delete(x-1,y);
    delete(x-1,y+1);
  end;
end;
begin
  assign(input,'skill.in');
  reset(input);
  assign(output,'skill.out');
  rewrite(output);
  readln(n,m);
  for i:=1 to n do
  begin
    for j:=1 to n-i+1 do
      read(a[i,j]);
    readln;
  end;
  suan;
  if m>=ceng[n] then
  begin
    writeln(f[n,1].wei);
    close(input);
    close(output);
    halt;
  end;
  max:=0;
  while m>0 do
  begin
    r:=0;
    s:=0;
    t:=0;
    for i:=1 to n do
      for j:=1 to n-i+1 do
        if (f[i,j].dian<=m)and(f[i,j].dian>0) then
        if (f[i,j].wei/f[i,j].dian)>r then
        begin
          r:=f[i,j].wei/f[i,j].dian;
          s:=i;
          t:=j;
        end;
    max:=max+f[s,t].wei;
    m:=m-f[s,t].dian;
    delete(s,t);
    suan;
  end;
  writeln(max);
  close(input);
  close(output);
end.