fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. int area[13], count = 0;
  4. int cek(int row, int column)
  5. {
  6. int i;
  7. for (i = 1; i <= row - 1; ++i)
  8. {
  9. if (area[i] == column)
  10. return 0;
  11. else if (abs(area[i] - column) == abs(i - row))
  12. return 0;
  13. }
  14. return 1;
  15. }
  16. void bomb(int row, int n)
  17. {
  18. int column = 0;
  19. for (column = 1; column <= n; ++column)
  20. {
  21. if (cek(row, column))
  22. {
  23. area[row] = column;
  24. if (row == n)
  25. ++count;
  26. else
  27. bomb(row + 1, n);
  28. }
  29. }
  30. }
  31. int main()
  32. {
  33. int n;
  34. scanf("%d", &n);
  35. bomb(1, n);
  36. printf("%d", count);
  37. return 0;
  38. }
Success #stdin #stdout 0s 5496KB
stdin
4
stdout
2