比赛 20121106 评测结果 AWWAWWWWAWWWWWW
题目名称 二十一点 最终得分 20
用户昵称 亟隐 运行时间 0.484 s
代码语言 Pascal 内存使用 0.16 MiB
提交时间 2012-11-06 11:39:16
显示代码纯文本
var     f,a:array[-10..1100]of longint;
        n,i,j,x,y,k:longint;

procedure init;
begin
        readln(n);
        for i:=1 to n do read(a[i]);
        for i:=1 to n do f[i]:=-100000000;
end;

function try(x,y,l,r,k,b,b2:longint):boolean;
begin
        if l>r then
        begin
                if f[i]<-1000000 then f[i]:=0;
                if x>=y then exit(false) else exit(true);
        end;
        if (x>21)or(y>21) then exit(false);
        if (b=0)and(b2=0) then exit(false);
        if k=0 then
        begin
                if (b=1)and(x<=16) then if try(x+a[l],y,l+1,r,1-k,b,b2) then exit(true);
                exit(try(x,y,l,r,1-k,0,b2));
        end else
        begin
                if b2=1 then if try(x,y+a[l],l+1,r,1-k,b,b2) then exit(true);
                exit(try(x,y,l,r,1-k,b,0));
        end;
        exit(false);
end;

function deal(l,r:longint):boolean;
begin
        x:=a[l]+a[l+2]; y:=a[l+1]+a[l+3];
        l:=l+4;
        exit(try(x,y,l,r,0,1,1));
end;

procedure work;
begin
        for i:=1 to n do
                for j:=0 to i-6 do
                begin
                        if f[j]+1>f[i] then if deal(j+1,i) then f[i]:=f[j]+1;
                        if (f[i]<-10000000)and(f[j]>=0) then deal(j+1,i);
                end;
        x:=0;
        for i:=1 to n do if f[i]>x then x:=f[i];
        writeln(x);
end;

begin
assign(input,'jack.in');reset(input);
assign(output,'jack.out');rewrite(output);
        init;
        work;
close(input);close(output);
end.