比赛 |
20121106 |
评测结果 |
AAAWWWAWAWWWWWW |
题目名称 |
二十一点 |
最终得分 |
33 |
用户昵称 |
乔治文 |
运行时间 |
0.022 s |
代码语言 |
Pascal |
内存使用 |
3.99 MiB |
提交时间 |
2012-11-06 11:58:58 |
显示代码纯文本
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-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
begin
for j:=1 to i do
if b[j,i]=1
then begin
if f[i]<f[j-1]+1
then f[i]:=f[j-1]+1
end;
end;
for i:=i-5 to n do
if f[n]<f[i]
then f[n]:=f[i];
writeln(f[n]);
close(input);
close(output);
end.