比赛 10101115 评测结果 AAATWWWWWW
题目名称 技能树 最终得分 30
用户昵称 ZhouZn1 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-15 11:23:33
显示代码纯文本
program zzn;
        type
arr=array[1..50]of integer;
var
        m,n,i,j,ans:longint;
        a,b:array[1..50,1..50]of longint;
        er:array[0..50]of arr;
procedure init;
begin
        assign(input,'skill.in');
        reset(input);
        assign(output,'skill.out');
        rewrite(output);
        readln(n,m);
        for i:=n downto 1 do
         begin
            for j:=1 to i do
            read(a[n-i+1,j]);
            readln;
         end;
        b:=a;
        for i:=2 to n do
         begin
             for j:=1 to n-i+1 do
              b[i,j]:=b[i,j]+b[i-1,j]+b[i-1,j+1];
         end;
        for i:=1 to 50 do er[0,i]:=1;
end;
procedure closef;
begin
        close(input);
        close(output);
end;
function min(x,y:integer):integer;
begin
    if x<y then exit(x) else exit(y);
end;
procedure change(n,x:integer;var c:arr);
var
        i:integer;
begin
        fillchar(c,sizeof(c),0);
        i:=n+1;
        while x<>0 do
        begin
            dec(i);
            c[i]:=x mod 2;
            x:=x shr 1;
        end;
end;
function can(n:integer;c:arr):integer;
var
        i,s:integer;
begin
        s:=0;
        for i:=1 to n do
         if c[i]=1 then inc(s);
        exit(s);
end;
function ok(x:integer;c:arr):boolean;
var
        i:integer;
begin
        for i:=1 to x do
         if ((c[i]=1)and(er[x-1,i]=0))or((c[i]=1)and(er[x-1,i+1]=0)) then
          exit(false);
        exit(true);
end;

procedure  dep(x:integer;hp,wei:longint);
var
        i,ne,j:integer;
        w,s:longint;
begin
        s:=trunc( exp( (n-x+1)*ln(2)))-1;
        for i:=1 to  s do
        begin
            change(n-x+1,i,er[x]);
            ne:=can(n-x+1,er[x]);
            if ne>hp then exit;
            if ok(x,er[x])then
             begin
               w:=0;
               for j:=1 to n-x+1 do inc(w,er[x,j]*a[x,j]);
               if wei+w>ans then ans:=wei+w;
               dep(x+1,hp-ne,wei+w);

             end;
        end;
end;
procedure main;
begin
        if (n+1)*n shr 1<=m then
         begin
             writeln(b[n,1]);
             exit;
         end;
        ans:=0;
        dep(1,m,0);
        writeln(ans);
end;
begin
        init;
        main;
        closef;
end.