以下是程序清单:
var i,j,count,n:longint;
==============================================================
function check(i,sum:longint):boolean;
var a,b,c,j,w,t:longint;
begin
w:=sum;
t:=0;
for j:=1 to i do begin t:=t shl 1+(w and 1);w:=w shr 1;end;
for j:=1 to i div 3 do
begin w:=t;
a:=w and (1 shl j-1);
w:=w shr j;
b:=w and (1 shl j-1);
w:=w shr j;
c:=w and (1 shl j-1);
if (a=b)and(a=c) then exit(false);
end;
exit(true);
end;
=============================================================
procedure search(i,sum:longint);
begin
if i>n then begin inc(count);exit;end;
if check(i,sum) then search(i+1,sum);
if check(i,sum+1 shl (i-1)) then search(i+1,sum+1 shl (i-1));
end;
=============================================================
begin
readln(n);
if n=1 then begin writeln(2);halt;end;
search(2,0);
writeln(2*count);
end.
===============做人要厚道,自己有脑子============================