#include using namespace std; const int N = 10; int a[N]; bool st[N]; int n = 3; void dfs(int u) { if (u == n + 1) { for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl; return; } for (int i = 1; i <= n; i++) if (!st[i]) { a[u] = i; st[i] = true; dfs(u + 1); st[i] = false; } } int main() { dfs(1); return 0; }