fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n,ans;
  5. bool col[12];
  6. bool cheo1[24];
  7. bool cheo2[24];
  8.  
  9. void quaylui(int hang){
  10. if(hang > n){
  11. ans++;
  12. return;
  13. }
  14. for(int cot = 1; cot <= n; cot++){
  15. if(!col[cot] && !cheo1[hang + cot] && !cheo2[hang - cot + n]){
  16. col[cot]= true;
  17. cheo1[hang + cot] = true;
  18. cheo2[hang - cot + n] = true;
  19.  
  20. quaylui(hang + 1);
  21.  
  22. col[cot]= false;
  23. cheo1[hang + cot] = false;
  24. cheo2[hang - cot + n] = false;
  25. }
  26. }
  27. }
  28.  
  29. int main(){
  30. cin >> n;
  31. quaylui(1);
  32. cout << ans;
  33. }
  34.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
1