记录编号 80133 评测结果 AAAAAAAAAAA
题目名称 [USACO Feb08] 麻烦的聚餐 最终得分 100
用户昵称 Gravatar正确率超低的渣渣 是否通过 通过
代码语言 Pascal 运行时间 0.015 s
提交时间 2013-11-06 19:44:23 内存使用 0.62 MiB
显示代码纯文本
  program egroup (input,output);
  var
  n,i,j,t,ans:longint;
  d:array[0..30001] of longint;
  a:array[0..30001,1..3] of longint;
  function min (x,y:longint):longint;
  begin
  if x<y then min:=x
         else min:=y;
  end;

  begin
  assign(input, 'egroup.in');
  reset(input);
  assign(output,'egroup.out');
  rewrite(output);

  readln(n);
  ans:=0;
  fillchar(a,sizeof(a),126);
  for i:=1 to n do
    readln(d[i]);

  for i:=1 to 3 do
    a[0,i]:=0;

  for i:=1 to n do
  for j:=1 to 3 do
  for t:=1 to j do
  if j=d[i] then  a[i,j]:=min(a[i,j],a[i-1,t])
            else  a[i,j]:=min(a[i,j],a[i-1,t]+1);

 ans:=a[n,1];
 for i:=2 to 3 do
 ans:=min (ans,a[n,i]);


  fillchar(a,sizeof(a),126);

    for i:=1 to 3 do
  a[0,i]:=0;

   for i:=1 to n do
  for j:=1 to 3 do
  for t:=j to 3 do
  if j=d[i] then  a[i,j]:=min(a[i,j],a[i-1,t])
            else  a[i,j]:=min(a[i,j],a[i-1,t]+1);

 for i:=1 to 3 do
 ans:=min (ans,a[n,i]);




  writeln(ans);

  close(input);
  close(output);
 end.