fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. bool valid(int arr[8][8],int r,int c){
  4. if(r>=0 and r<8 and c>=0 and c<8 and arr[r][c]== -1)
  5. return true;
  6. return false;
  7. }
  8. void fun(int arr[8][8],int r,int c,int x){
  9. if(x==64){
  10. cout<<"***********************ARRAY FOUND***********************\n";
  11. for(int i=0;i<8;i++){
  12. for(int j=0;j<8;j++)
  13. cout<<arr[i][j]<<" ";
  14. cout<<"\n";
  15. }
  16. return;
  17. }
  18. if(!valid(arr,r,c))
  19. return;
  20. arr[r][c] = x;
  21. fun(arr,r-2,c+1,x+1); fun(arr,r-2,c-1,x+1);
  22. fun(arr,r-2,c+2,x+1); fun(arr,r-2,c-2,x+1);
  23. fun(arr,r+2,c+1,x+1); fun(arr,r+2,c-1,x+1);
  24. fun(arr,r+1,c+2,x+1); fun(arr,r+1,c-2,x+1);
  25. arr[r][c] = -1;
  26. }
  27. int main() {
  28. int arr[8][8] ;
  29. for(int i=0;i<8;i++){
  30. for(int j=0;j<8;j++)
  31. arr[i][j] = -1;
  32. }
  33. int r=0,c=0,x=0; fun(arr,r,c,x);
  34. }
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
Time limit exceeded #stdin #stdout 5s 4400KB
stdin
Standard input is empty
stdout
Standard output is empty