[scoi2005]扫雷

program bzoj1088;
var n,i,a1,a2,flag:longint;
    ans:int64;
	a,b:array[1..10000]of integer;
begin
 read(n);
 for i:=1 to n do read(b[i]);
 for a1:=0 to 1 do//确定前两个即可
  for a2:=0 to 1 do
   begin
    a[1]:=a1;a[2]:=a2;
	flag:=1;
	if b[1]<>a[1]+a[2] then flag:=0;
	for i:=3 to n do
	 begin
	  if flag=0 then break;
	  a[i]:=b[i-1]-a[i-1]-a[i-2];
	  if (a[i]>1)or(a[i]<0)  then 
	   begin
	    flag:=0;
		break;
	   end;
	 end;
	if b[n]<>a[n]+a[n-1] then flag:=0;//递推+判断最后是否合法
	ans:=ans+flag;
   end;
 writeln(ans);
end.

你可能感兴趣的:([scoi2005]扫雷)