close
Content
顧名思義,這題就是要你生出1∼N所有的排列。
Input
輸入只有一個正整數N。(1≤N≤10)
Output
請輸出1∼N的所有排列,每個排列都以一行N個數字輸出,並請按照字典序輸出。
兩個陣列a[1],a[2],…,a[N]和b[1],b[2],…,b[N] 如果滿足存在1≤k≤N使得a[1]=b[1],a[2]=b[2],…,a[k−1]=b[k−1]且a[k]<b[k],則a這個陣列的字典序比b小。
Sample Input #1
3
Sample Output #1
1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1
python:
from itertools import permutations
from sys import stdin
n=int(stdin.readline())
arr=[str(i) for i in range(1,n+1)]
p=permutations(arr)
for j in p:
print(' '.join(j))
文章標籤
全站熱搜