All pastes #340858 Raw Edit

Unnamed

public cpp v1 · immutable
·published 2007-02-05 02:23 UTC
rendered paste body
#include<iostream>/* Knight Tour */  const int size = 8;  void initialization();  void print();  void Knight ( int times, int row, int col );  bool K[size][size];  bool check( int row, int col);  int move_col[] = {-2, -1, +1, +2, +2, +1, -1, -2};  int move_row[] = {+1, +2, +2, +1, -1, -2, -2, -1};  int row, col, index, next_row, next_col;   int times;void initialization(){    index =0;    times = 0;    row = 0;    col = 0;       for ( int i=0; i < size; i++)    {        for ( int j=0; j < size; j++)        {            K[i][j] = false;        }    }  K[row][col] = true;}bool check ( int row, int col ){    if ( row > 7 || row < 0 || col > 7 || col < 0 || K[row][col] == true )        return false;    else        return true;}void print (){    index++;    cout << " Let's go Knight ^^" << endl;    cout << " The : "<< index << "th"<< endl;    for ( int k = 0; k < size; k++ )    {        for ( int m = 0; m < size; m++ )        {              if ( K[k][m] == true )              {                    cout << " K " ;                             }                  else                 cout << " * ";        }    cout << endl;    }}void Knight ( int times, int row, int col){            if ( times == 64 )          print();      else      {              for ( int i = 0; i < 8; i++ )                {                                cout << " col : " << col << endl;                  cout << " row : " << row << endl;                                               next_col = col + move_col[i];                  next_row = row + move_row[i];                                    cout << "next-----------:" << next_row << endl;                  cout << "next-----------:" << next_col << endl;                                    if (check( next_row,next_col ))                  {                                            K[next_row][next_col] = true;                        Knight (times+1, next_row, next_col);                      //K[next_row][next_col] = false;                  }                                }       }                 }                  void main(){   initialization();   Knight (0,0,0);int x;cin >> x;}