TopCoder

Adrien Wu
$ \begin{align} AC \times 2^9 \\ \text{New TIOJ ?} \end{align} $

User's AC Ratio

92.5% (62/67)

Submission's AC Ratio

45.9% (89/194)

Tags

Description

請設計一個電腦程式,可以計算從n個數字中(0, 1, 2, …, n-1)不重覆取出r個數字的所有排列方式 (1≤ r ≤ n ≤ 10),將所有排列所得的數字由小排到大,請問倒數第r + n個數字為何?

Input Format

輸入檔第一行有兩個正整數n與r,中間以空白分開,1≤ r ≤ n ≤ 10。

Output Format

請由螢幕印出倒數第r + n個數字,若所有排列的個數小於r + n,則請列出最小數字(即第一個數字)。

Sample Input 1

5 2

Sample Output 1

31

Sample Input 2

4 3

Sample Output 2

231

Hints

Problem Source

原TIOJ1232 / TOI2005初選(prob 4)。

Subtasks

No. Testdata Range Score
1 0 20
2 1 20
3 2 20
4 3 20
5 4 20

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 65536 262144 1
1 1000 65536 262144 2
2 1000 65536 262144 3
3 1000 65536 262144 4
4 1000 65536 262144 5