Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int viz[30], n, d, sol[30];
- void Afisare()
- {
- for(int i = 1; i <= n; i++)
- cout << sol[i] << " ";
- cout << "\n";
- }
- void Back(int k)
- {
- if(k == n + 1)
- {
- Afisare();
- }
- for(int i = 1; i <= n; i++)
- {
- if(!viz[i] && abs(i - k) > d)
- {
- viz[i] = true;
- sol[k] = i;
- Back(k + 1);
- viz[i] = false;
- }
- }
- }
- int main()
- {
- cin >> n >> d;
- Back(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement