记录编号 48832 评测结果 AAAAAAAAAWWWWWW
题目名称 二十一点 最终得分 60
用户昵称 Gravatarbw 是否通过 未通过
代码语言 Pascal 运行时间 0.008 s
提交时间 2012-11-06 18:00:32 内存使用 0.17 MiB
显示代码纯文本
program ex;
  var f,data:array[0..1000] of longint;
  n,i,j,k,ans,biao,tt,sum1,sum2:longint;
  function max(x,y:longint):longint;
   begin
    if x>y then exit(x); exit(y);
   end;
   begin
    assign(input,'jack.in');
    assign(output,'jack.out');
    reset(input);
    rewrite(output);
     read(n);
      for i:=1 to n do
       read(data[i]);
       fillchar(f,sizeof(f),255);
       f[0]:=0;
      for i:=1 to n-5 do
         if f[i-1]<>-1 then
          for j:=0 to 19 do
          begin
          tt:=0;
           biao:=i+4;
           sum1:=data[i]+data[i+2];
           sum2:=data[i+1]+data[i+3];
           while (sum1<=16)or(j>tt) do
           begin
            if (sum1>21) or(sum2>21) then break;
            if sum1<=16 then
            begin
            sum1:=sum1+data[biao];  inc(biao); if biao>n then break; end;
            if (sum1>16)  and(sum2>sum1) then break;
            if tt<j then begin sum2:=sum2+data[biao];
            inc(tt); inc(biao);
            if biao>n then break; end;
           end;
           if ((sum1>=sum2) and(sum1<=21))
           or(sum2>21)
           then f[biao-1]:=max(f[i-1],f[biao-1])
           else f[biao-1]:=max(f[i-1]+1,f[biao-1]);
          end;
    for i:=n-4 to n do
       if f[i]>ans then ans:=f[i];
    writeln(ans);
  {  for i:=1 to n do
     write(f[i],' ');}
    close(input); close(output);
    end.