Advertisement
huutho_96

Đệ Quy 8 Hậu

May 6th, 2015
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. //https://www.facebook.com/pages/C%C3%B9ng-h%E1%BB%8Dc-l%E1%BA%ADp-tr%C3%ACnh/632038696941833
  2. #include <iostream>
  3. #include <conio.h>
  4. using namespace std;
  5. int dem1 = 0;
  6. int hang[8], cot[8], cheo1[15], cheo2[15];
  7. int nuoc[2][8];
  8. int Try(int i, int j)
  9. {
  10. if (hang[i] != 1 && cot[j] != 1 && cheo1[i + j] != 1 && cheo2[i - j + 7] != 1) return 1;
  11. return 0;
  12. }
  13. void DatQuan(int i, int j, int x)
  14. {
  15. hang[i] = x;
  16. cot[j] = x;
  17. cheo1[i + j] = x;
  18. cheo2[i - j + 7] = x;
  19. }
  20. void Tim(int i, int k, int dem)
  21. {
  22. if (dem == 8)
  23. {
  24. for (int h = 0; h < 8; h++)
  25. cout << nuoc[1][h] << '\t' << nuoc[0][h] << endl;
  26. getch();
  27. system("cls");
  28. return;
  29. }
  30. for (int j = 0; j < 8; j++)
  31. {
  32. if (Try(i, j) == 1)
  33. {
  34. nuoc[0][i] = i;
  35. nuoc[1][i] = j;
  36. if (i == 8)
  37. {
  38. return;
  39. }
  40. DatQuan(i, j, 1);
  41. Tim(i + 1, j, dem + 1);
  42. }
  43. else
  44. continue;
  45. DatQuan(i, j, 0);
  46. }
  47. }
  48. void main()
  49. {
  50. Tim(0, 0, 0);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement