Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. public class Q9663 {
  2. static int[] arr;
  3. static int answer;
  4. static int num;
  5.  
  6. public static void main(String[] args) {
  7. Scanner sc = new Scanner(System.in);
  8. num = sc.nextInt();
  9. arr=new int[num];
  10. findnumQ(arr, num, 0);
  11. System.out.println(answer);
  12. }
  13.  
  14. static boolean promising(int[] arr,int num,int row) {
  15. for(int i=0; i<row; i++) {
  16. if(arr[row] == arr[i] || row-i == Math.abs(arr[row]-arr[i])) {
  17. return false;
  18. }
  19. }
  20. return true;
  21. }
  22. static void findnumQ(int[] arr,int num,int row) {
  23. for(int i=0;i<num;i++) {
  24. arr[row]=i;
  25. if(promising(arr, num, row)) {
  26. if(row==num-1) {
  27. answer++;
  28. }else {
  29. findnumQ(arr, num, row+1);
  30. }
  31. }
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement