记录编号 |
79612 |
评测结果 |
AWWAAAAWAWA |
题目名称 |
[USACO Feb08] 麻烦的聚餐 |
最终得分 |
63 |
用户昵称 |
Alan |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
0.010 s |
提交时间 |
2013-11-05 23:27:58 |
内存使用 |
0.50 MiB |
显示代码纯文本
var
b:array[-1..30010]of integer;
a:array[-1..30010,0..4]of integer;
l,n,i,j,max:integer;
begin
assign(input,'egroup.in');
assign(output,'egroup.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do
readln(b[i]);
for j:=1 to 3 do
if b[1]=j then
a[1,j]:=0
else
a[1,j]:=1;
for i:=2 to n do
for j:=1 to 3 do
begin
a[i,j]:=30001;
if b[i]=j then
begin
if (j-1<1) or (a[i-1,j-1]>=a[i-1,j]) then
l:=a[i-1,j]
else l:=a[i-1,j-1];
if l<a[i,j] then a[i,j]:=l;
end
else
begin
if (j-1<1) or (a[i-1,j-1]>=a[i-1,j]) then
l:=a[i-1,j]+1
else l:=a[i-1,j-1]+1;
if l<a[i,j] then a[i,j]:=l;
end;
end;
max:=a[n,3];
for j:=1 to 3 do
if b[n]=j then
a[n,j]:=0
else
a[n,j]:=1;
for i:=n-1 downto 1 do
for j:=1 to 3 do
begin
a[i,j]:=30001;
if b[i]=j then
begin
if (j-1<1) or (a[i+1,j-1]>=a[i+1,j]) then
l:=a[i+1,j]
else
l:=a[i+1,j-1];
if l<a[i,j] then a[i,j]:=l;
end
else
begin
if (j-1<1) or (a[i+1,j-1]>=a[i+1,j]) then
l:=a[i+1,j]+1
else
l:=a[i+1,j-1]+1;
if l<a[i,j] then a[i,j]:=l;
end;
end;
if max>a[1,3] then
max:=a[1,3];
writeln(max);
close(input);
close(output);
end.