Page 63 - C:\Users\Admin\Desktop\Sach mem upweb\
P. 63

100 Problems & Solutions                                                Trang 63


                        dd[i,j] := 0;
                        If dd[i,j-1] = 0 then Xetbot(i,j-1);
                        If dd[i,j+1] = 0 then Xetbot(i,j+1);
                        If dd[i-1,j] = 0 then Xetbot(i-1,j);
                        If dd[i+1,j] = 0 then Xetbot(i+1,j);
                      End;

                      Procedure Xethangcot( ii : integer );
                      Var  i ,j    :integer;
                      Begin
                        i := qi[ii];
                        j := qj[ii];
                        Inc(hang[i]);
                        If hang[i] = 1 then Dec(hangthieu);
                        Inc(cot[j]);
                        If cot[j] = 1 then Dec(cotthieu);
                      End;

                      Procedure Xetlaihangcot( ii : integer );
                      Var  i,j :    integer;
                      Begin
                        i := qi[ii];
                        j := qj[ii];
                        If hang[i] = 1 then Inc(hangthieu);
                        Dec(hang[i]);
                        If cot[j] = 1 then Inc(cotthieu);
                        Dec(cot[j]);
                      End;

                      Procedure Duyet( i : integer;last : integer );
                      Var  ii :integer;
                      Begin
                      If i > n then
                         begin  thughinhancauhinh;  exit; end;
                      For ii := last + 1 to sl do
                         begin
                                themdiem(ii);
                                xethangcot(ii);
                                If hangthieu + cotthieu <= n - i then duyet(i+1,ii);
                                Xetlaihangcot(ii);
                                bodiem(ii);
                         end;
                      End;

                      Procedure Duyetcauhinh( i ,j : integer );
                      Var  jj :    integer;
                      Begin
                        sh := i;
                        sc := j;
                        FillChar(hang ,SizeOf(hang),0);



                      Tin học & Nhà trường                                       100 Đề Toán - Tin học
   58   59   60   61   62   63   64   65   66   67   68