推 tstanly:謝謝^^ 01/06 00:53
※ 編輯: cismjmgoshr 來自: 61.230.226.132 (01/06 01:05)
※ 引述《tstanly ()》之銘言:
: 大家好
: 想請問關於所有排列數的問題
: user可輸入元素大小 而每個元素有4種可能為0 1 2 3
: ex: user輸入元素大小為2
: 所有可能排列數為: 4^2=16
: 00 01 02 03
: 10 11 12 13
: 20 21 22 23
: 30 31 32 33
: ===============
: 請問這怎麼處理...想好久寫不出規則來
: 謝謝....
00 (base 4) = 0 (base 10)
01 (base 4) = 1 (base 10)
02 (base 4) = 2 (base 10)
03 (base 4) = 3 (base 10)
10 (base 4) = 4 (base 10)
11 (base 4) = 5 (base 10)
12 (base 4) = 6 (base 10)
13 (base 4) = 7 (base 10)
20 (base 4) = 8 (base 10)
21 (base 4) = 9 (base 10)
22 (base 4) = 10 (base 10)
23 (base 4) = 11 (base 10)
30 (base 4) = 12 (base 10)
31 (base 4) = 13 (base 10)
32 (base 4) = 14 (base 10)
33 (base 4) = 15 (base 10)
也就是說,把 0 ~ 4^N-1這些數字,轉成base 4,然後從小到大列出來
--
∫work dt = success
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.230.226.132