记录编号 | 48686 | 评测结果 | AAWWAAWAAAWAWWW | ||
---|---|---|---|---|---|
题目名称 | 二十一点 | 最终得分 | 53 | ||
用户昵称 | 是否通过 | 未通过 | |||
代码语言 | Pascal | 运行时间 | 0.006 s | ||
提交时间 | 2012-11-06 14:01:51 | 内存使用 | 0.37 MiB | ||
program p1250; uses math; var a,f:array[0..10000]of longint; n,i,z,p,l,turn,r,zz:longint; 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:=n downto n-4 do f[i]:=0; for i:=n-5 downto 1 do begin z:=0;p:=0; inc(z,a[i]);inc(z,a[i+2]); inc(p,a[i+1]);inc(p,a[i+3]); turn:=1; r:=i+3; while r<n do case turn of 1:begin if (z<=16)and(r<n) then begin inc(r); inc(z,a[r]); end; if z=21 then begin f[i]:=max(f[i],f[r+1]); break; end; if z>21 then begin f[i]:=max(f[i],f[r+1]+1); break; end; turn:=0; end; 0:begin if (p>z)and(z>16) then begin f[i]:=max(f[i],f[r+1]+1); break; end; l:=r; zz:=z; while (z<=16)and(l<n) do begin inc(l); inc(z,a[l]); end; if z>21 then begin f[i]:=max(f[i],f[l+1]+1); break; end else if p>z then f[i]:=max(f[i],f[l+1]+1) else f[i]:=max(f[i],f[l+1]); z:=zz; if r<n then begin inc(r); inc(p,a[r]); end; if p>21 then begin f[i]:=max(f[i],f[r+2]); break; end; turn:=1; if r=n then if(p>z) then begin f[i]:=max(f[i],1); break; end else begin f[i]:=max(f[i],0); break; end; end; end; end; write(f[1]); close(input); close(output); end.