比赛 |
20111102 |
评测结果 |
AAAAAAAAAAA |
题目名称 |
麻烦的聚餐 |
最终得分 |
100 |
用户昵称 |
reamb |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-11-02 19:09:32 |
显示代码纯文本
program mafandejucan;
var
f:array[1..30000,1..3]of longint;
i,j,k,n,min,m:longint;
d:array[1..30000]of integer;
begin
assign (input,'egroup.in');
reset (input);
readln (n);
for i:=1 to n do
readln (d[i]);
close (input);
for i:=1 to 3 do
if i=d[1] then
f[1,i]:=0
else
f[1,i]:=1;
for i:=2 to n do
for j:=1 to 3 do
begin
min:=maxlongint;
if j=d[i] then
for k:=1 to j do
if f[i-1,k]<min then
min:=f[i-1,k];
if j<>d[i] then
for k:=1 to j do
if f[i-1,k]+1<min then
min:=f[i-1,k]+1;
f[i,j]:=min
end;
m:=maxlongint;
for i:=1 to 3 do
if f[n,i]<maxlongint then
m:=f[n,i];
for i:=1 to 3 do
if i=d[1] then
f[1,i]:=0
else
f[1,i]:=1;
for i:=2 to n do
for j:=1 to 3 do
begin
min:=maxlongint;
if j=d[i] then
for k:=3 downto j do
if f[i-1,k]<min then
min:=f[i-1,k];
if j<>d[i] then
for k:=3 downto j do
if f[i-1,k]+1<min then
min:=f[i-1,k]+1;
f[i,j]:=min
end;
for i:=1 to 3 do
if f[n,i]<m then
m:=f[n,i];
assign (output,'egroup.out');
rewrite (output);
writeln (m);
close (output)
end.