Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int st[100], i, n, f = 1;
- char a[10][30];
- void backtrack(int k)
- {
- if(k == n+1)
- {
- for(i = 1; i <= n; i++)
- cout << a[st[i]] << " ";
- cout << "\n";
- }
- else
- {
- st[k] = 0;
- while(st[k]++ < n)
- {
- f = 1;
- for(i = 1; i < k; i++)
- if(st[i] == st[k])
- f = 0;
- if(f) backtrack(k+1);
- }
- }
- }
- int main()
- {
- cin >> n; cin.get();
- for(i = 1; i <= n; i++)
- {
- cin.get(a[i], 30);
- cin.get();
- }
- backtrack(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement