fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool check(vector<vector<bool> >arr,int row,int col,int n)
  5. {
  6. for(int i=0;i<row;i++)
  7. {
  8. if(arr[i][col])
  9. {
  10. return false;
  11. }
  12. }
  13. for(int j=0;j<col;j++)
  14. {
  15. if(arr[row][j])
  16. {
  17. return false;
  18. }
  19. }
  20.  
  21. for(int i=row;int j=col;i>=0 && j>=0;i--,j--)
  22. {
  23. if(arr[i][j])
  24. {
  25. return false;
  26. }
  27. }
  28.  
  29. for(int i=row;int j=col;i>=0 &&j<col;i--,j++)
  30. {
  31. if(arr[i][j])
  32. {
  33. return false;
  34. }
  35. }
  36. return true;
  37. }
  38.  
  39.  
  40.  
  41.  
  42. bool bck(vector< vector<bool> >arr,int n,int row)
  43. {
  44. if(row<=N)
  45. {
  46. return true;
  47. }
  48.  
  49.  
  50. for(int i=0;i<n;i++)
  51. {
  52. if(check(arr,row,i,n))
  53. {
  54. arr[row][col] = true;
  55.  
  56.  
  57. if(bck(arr,n,row+1))
  58. {
  59. return true;
  60. }
  61. }
  62.  
  63. }
  64. return false;
  65. }
  66.  
  67.  
  68.  
  69. int main()
  70. {
  71. int n;
  72. cin>>n;
  73. vector< <vector<bool> >arr(n,vector<bool>(n));
  74. if(bck(arr,n,0)==true)
  75. {
  76. for(int i=0;i<n;i++)
  77. {
  78. for(int j=0;j<n;j++)
  79. {
  80. cout<<arr[i][j]<<" ";
  81. }
  82. cout<<endl;
  83. }
  84. }
  85. return 0;
  86. }
  87.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘bool check(std::vector<std::vector<bool> >, int, int, int)’:
prog.cpp:21:41: error: expected ‘)’ before ‘;’ token
     for(int i=row;int j=col;i>=0 && j>=0;i--,j--)
                                         ^
prog.cpp:21:42: error: ‘i’ was not declared in this scope
     for(int i=row;int j=col;i>=0 && j>=0;i--,j--)
                                          ^
prog.cpp:21:46: error: ‘j’ was not declared in this scope
     for(int i=row;int j=col;i>=0 && j>=0;i--,j--)
                                              ^
prog.cpp:29:41: error: expected ‘)’ before ‘;’ token
     for(int i=row;int j=col;i>=0 &&j<col;i--,j++)
                                         ^
prog.cpp: In function ‘bool bck(std::vector<std::vector<bool> >, int, int)’:
prog.cpp:44:13: error: ‘N’ was not declared in this scope
     if(row<=N)
             ^
prog.cpp:54:18: error: ‘col’ was not declared in this scope
         arr[row][col] = true;
                  ^~~
prog.cpp: In function ‘int main()’:
prog.cpp:73:48: error: template argument 1 is invalid
    vector< <vector<bool> >arr(n,vector<bool>(n));
                                                ^
prog.cpp:73:48: error: template argument 2 is invalid
prog.cpp:74:11: error: ‘arr’ was not declared in this scope
    if(bck(arr,n,0)==true)
           ^~~
stdout
Standard output is empty