#491. DFS - 全排列(经典入门)
DFS - 全排列(经典入门)
题目描述
给定一个整数 n,输出 1~n 的所有全排列(按字典序)。
输入格式
一行一个整数 n(1 ≤ n ≤ 8)。
输出格式
若干行,每行一个排列,数字间空格隔开。
示例
输入:
3
输出
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
给定一个整数 n,输出 1~n 的所有全排列(按字典序)。
一行一个整数 n(1 ≤ n ≤ 8)。
若干行,每行一个排列,数字间空格隔开。
示例
3
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
By signing up a Hydro universal account, you can submit code and join discussions in all online judging services provided by us.