Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int viz[30], n, d, sol[30];
  6.  
  7. void Afisare()
  8. {
  9. for(int i = 1; i <= n; i++)
  10. cout << sol[i] << " ";
  11. cout << "\n";
  12.  
  13. }
  14.  
  15. void Back(int k)
  16. {
  17. if(k == n + 1)
  18. {
  19. Afisare();
  20. }
  21. for(int i = 1; i <= n; i++)
  22. {
  23. if(!viz[i] && abs(i - k) > d)
  24. {
  25. viz[i] = true;
  26. sol[k] = i;
  27. Back(k + 1);
  28. viz[i] = false;
  29. }
  30.  
  31. }
  32.  
  33.  
  34. }
  35.  
  36.  
  37.  
  38. int main()
  39. {
  40. cin >> n >> d;
  41. Back(1);
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement