Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## Re:没问题吧。我就是从左往右串的，也是从左往右搜的，就过了。

Posted by lydliyudong at 2011-07-04 20:54:38 on Problem 3279
In Reply To:貌似题目里定义的字典序有点问题 Posted by:Felicia at 2007-12-24 21:12:17
```RT

var
a,b:array[0..16,0..16]of longint;
c,d,e:array[0..16,0..16]of boolean;
n,m,i,j,ans:longint;
bool:boolean;
procedure click(x,y:longint);
begin
a[x,y]:=1-a[x,y];
a[x+1,y]:=1-a[x+1,y];
a[x-1,y]:=1-a[x-1,y];
a[x,y+1]:=1-a[x,y+1];
a[x,y-1]:=1-a[x,y-1];
c[x,y]:=true;
end;
procedure resume(x,y:longint);
begin
a[x,y]:=1-a[x,y];
a[x+1,y]:=1-a[x+1,y];
a[x-1,y]:=1-a[x-1,y];
a[x,y+1]:=1-a[x,y+1];
a[x,y-1]:=1-a[x,y-1];
c[x,y]:=false;
end;
procedure dfs2(temp:longint);
var
i,j:longint;
begin
if temp>=ans then exit;
b:=a; d:=c;
for i:=1 to n-1 do
for j:=1 to m do
if a[i,j]=1 then
begin
inc(temp);
if temp>=ans then break;
click(i+1,j);
end;
if temp<ans then
begin
bool:=true;
for i:=1 to n do
for j:=1 to m do
if a[i,j]=1 then
begin bool:=false; break; end;
if bool then
begin ans:=temp; e:=c; end;
end;
a:=b; c:=d;
end;
procedure dfs1(x,temp:longint);
begin
if x>m then begin dfs2(temp); exit; end;
dfs1(x+1,temp);
click(1,x);
dfs1(x+1,temp+1);
resume(1,x);
end;
begin
for i:=1 to n do
for j:=1 to m do
ans:=maxlongint;
dfs1(1,0);
//writeln(ans);
if ans=maxlongint then writeln('IMPOSSIBLE')
else for i:=1 to n do
begin
for j:=1 to m-1 do
if e[i,j] then write(1,' ') else write(0,' ');
if e[i,m] then writeln(1) else writeln(0);
end;
end.

```

Followed by: