记录编号 48768 评测结果 AAWAAAAAAWWWWWW
题目名称 二十一点 最终得分 53
用户昵称 Gravatar乔治文 是否通过 未通过
代码语言 Pascal 运行时间 0.027 s
提交时间 2012-11-06 15:35:06 内存使用 3.99 MiB
显示代码纯文本
var i,j,n,p,temp1,temp2:longint;
    b:array[0..1000,0..1000] of longint;
    f,a:array[0..1000] of longint;

procedure search(k,temp1,temp2,t,flag:longint);
begin
if k>n
 then begin
       if (temp1<=21)and(temp1>=temp2)
        then b[i,k-1]:=0
        else b[i,k-1]:=1;
       exit;
      end;
if t=1
 then begin
       if temp1<=16
        then search(k+1,temp1+a[k],temp2,2,flag)
        else begin
              if flag=1
               then begin
                     if (temp1<=21)and(temp1>=temp2)
                      then b[i,k-1]:=0
                      else b[i,k-1]:=1;
                    end
               else search(k,temp1,temp2,2,flag);
             end;
      end
 else begin

       if (temp2+a[k]<=21)and(flag=0)
        then search(k+1,temp1,temp2+a[k],1,flag);
       search(k,temp1,temp2,1,1);
      end;
end;
begin
assign(input,'jack.in');
reset(input);
assign(output,'jack.out');
rewrite(output);
read(n);
for i:=1 to n do
 read(a[i]);
for i:=1 to n do
 for j:=1 to n do
  b[i,j]:=-1;
for i:=1 to n-5 do
 begin
  p:=i+4;
  temp1:=a[i]+a[i+2];
  temp2:=a[i+1]+a[i+3];
  search(p,temp1,temp2,1,0);
 end;
 for i:=1 to n do
  f[i]:=-1000;
for i:=1 to n do
 begin

  for j:=1 to i do
   if (b[j,i]>=0)
    then begin
          if f[i]<f[j-1]+b[j,i]
           then f[i]:=f[j-1]+b[j,i];
           if f[i]=1
            then f[i]:=f[i];
         end

 end;
for i:=i-4 to n do
 if f[n]<f[i]
  then f[n]:=f[i];
writeln(f[n]);
close(input);
close(output);

end.