做模拟赛受虐了,切usaco玩。
1: program bzoj1609;
2: uses math;
3: const maxn=30000;
4: var i,n,ans:longint;
5: f:array[0..maxn,1..3] of longint;
6: D:array[0..maxn] of longint;
7: procedure swap(var a,b:longint);
8: var t:longint;
9: begin t:=a;a:=b;b:=t;end;
10: procedure DP;
11: var i,j,k:longint;
12: begin
13: filldword(f,sizeof(f)>>2,maxlongint);
14: F[0][1]:=0;F[0][2]:=0;F[0][3]:=0;
15: for i:=1 to n do
16: for j:=1 to 3 do
17: for k:=1 to j do
18: if D[i]=j
19: then F[i][j]:=min(F[i-1][k], F[i][j])
20: else F[i][j]:=min(F[i-1][k]+1,F[i][j]);
21: ans:=min(min(F[n][1],F[n][2]),F[n][3]);
22: end;
23: begin
24: readln(n);ans:=maxlongint;
25: for i:=1 to n do readln(D[i]);DP;
26: for i:=1 to n>>1 do swap(D[i],D[n-i+1]);DP;
27: writeln(ans);
28: end.
29: