Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  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
 readln(n,m);
 for i:=1 to n do
  for j:=1 to m do
   read(a[i,j]);
 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:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator