减小规模后采用穷举法:
{扫雷:3=
var
r:registers;
n:integer;
a,b:array[1..16] of integer;
c:array[1..16] of integer;
i,j,k:integer;
f:text;
begin
assign(f,'sweep.in'); reset(f);
readln(f,n);
for i:=n downto 1 do read(f,a[i]);
for i:=n+1 to 16 do a[i]:=0;
close(f);
r.ax:=0;
repeat
r.bx:=r.ax;
b[1]:=3 and r.bx;
case b[1] of
0:b[1]:=0;
1,2:b[1]:=1;
3:b[1]:=2;
end;
b[2]:=7 and r.bx;
case b[2] of
0:b[2]:=0;
1,2,4:b[2]:=1;
3,5,6:b[2]:=2;
7:b[2]:=3;
end;
for i:=3 to n do begin
r.bx:=r.bx div 2;
b[i]:=7 and r.bx;
case b[i] of
0:b[i]:=0;
1,2,4:b[i]:=1;
3,5,6:b[i]:=2;
7:b[i]:=3;
end;
end;
k:=0;
for i:=1 to n do begin
if a[i]<>b[i] then inc(k);
end;
if k<>0 then inc(r.ax)
else break;
until r.ax=65536;
{ writeln(r.ax); }
r.bx:=r.ax;
for i:=1 to n do begin
c[i]:=r.bx mod 2;
r.bx:=r.bx div 2;
end;
for i:=n downto 1 do write(c[i]:1);
end.