e446. 排列生成
Tags : 遞迴
Accepted rate : 664人/885人 ( 75% ) [非即時]
評分方式:
Tolerant

最近更新 : 2019-11-22 18:11

Content

顧名思義,這題就是要你生出$1\sim N$所有的排列。

Input

輸入只有一個正整數$N$。($1\le N\le 10$)

 

Output

請輸出$1\sim N$的所有排列,每個排列都以一行$N$個數字輸出,並請按照字典序輸出。

兩個陣列$a[1], a[2], \ldots, a[N]$和$b[1], b[2], \ldots, b[N]$ 如果滿足存在$1\le k\le N$使得$a[1] = b[1], a[2] = b[2], \ldots, 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
測資資訊:
記憶體限制: 256 MB
公開 測資點#0 (10%): 1.0s , <1K
公開 測資點#1 (10%): 1.0s , <1K
公開 測資點#2 (10%): 1.0s , <1K
公開 測資點#3 (10%): 1.0s , <1K
公開 測資點#4 (10%): 1.0s , <1K
公開 測資點#5 (10%): 1.0s , <1K
公開 測資點#6 (10%): 1.0s , <1K
公開 測資點#7 (10%): 1.0s , <1K
公開 測資點#8 (10%): 1.0s , <1K
公開 測資點#9 (10%): 10.0s , <1K
Hint :
Tags:
遞迴
出處:
[管理者: ltf0501(ltfsjl) ]


ID User Problem Subject Hit Post Date
30872 a302854888@g...(小麥) e446
超意外
719 2022-06-17 20:43
26004 wubaie(小億) e446
692 2021-07-11 08:10
25910 wish.rirf@gm...(C++ 與我) e446
c++ 內建解
1266 2021-07-04 08:17
25656 asnewchien@g...(david) e446
python 影片分享
683 2021-06-10 11:54
25392 allllllan123...(God of Computer...) e446
putchar 才是王道
795 2021-05-18 21:02