记录编号 79429 评测结果 AAAAAAAAAAA
题目名称 [USACO Feb08] 麻烦的聚餐 最终得分 100
用户昵称 GravatarC语言入门 是否通过 通过
代码语言 Pascal 运行时间 0.014 s
提交时间 2013-11-05 18:02:44 内存使用 0.74 MiB
显示代码纯文本
var
 n,i,j,k,mina:longint;
 a,p:array [1..30000] of longint;
 f:array [1..30000,1..3] of longint;
function min(a,b:longint):longint;
begin
 if a>b then min:=b
        else min:=a;
end;
begin
assign (input,'egroup.in');
assign (output,'egroup.out');
reset (input);
rewrite (output);
 readln (n);
 for i:=1 to n do
  readln (a[i]);
 p:=a;
 fillchar (f,sizeof(f),127);
 for i:=1 to 3 do
  f[1,i]:=1;
 f[1,p[1]]:=0;
 for i:=2 to n do
  for j:=1 to 3 do
   begin
    for k:=1 to j do
     f[i,j]:=min(f[i,j],f[i-1,k]);
    if j<>p[i] then inc(f[i,j]);
   end;
 mina:=maxlongint;
 for i:=1 to 3 do
  mina:=min(mina,f[n,i]);
 for i:=n downto 1 do
  p[i]:=a[n-i+1];
 fillchar (f,sizeof(f),127);
 for i:=1 to 3 do
  f[1,i]:=1;
 f[1,p[1]]:=0;
 for i:=2 to n do
  for j:=1 to 3 do
   begin
    for k:=1 to j do
     f[i,j]:=min(f[i,j],f[i-1,k]);
    if j<>p[i] then inc(f[i,j]);
   end;
 for i:=1 to 3 do
  mina:=min(mina,f[n,i]);
 write (mina);
close (input);
close (output);
end.