Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int arr[4] = { 1,2,3,4 };
- int visited[4];
- void dfs(vector<int>& v) {
- auto sz = v.size();
- if (sz < 4) {
- for (int i = 0; i < 4; ++i) {
- if (!visited[i]) {
- v.push_back(arr[i]);
- visited[i] = 1;
- dfs(v);
- v.pop_back();
- visited[i] = 0;
- }
- }
- return;
- }
- for (auto& c : v)
- cout << c << ' ';
- cout << '\n';
- }
- int main() {
- vector<int> v;
- dfs(v);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment