← 返回 bytedance 的题目列表Choose k numbers from 1..n without repetition (combinations / permutations)
类型:online_judge
Given two integers n and k (1 <= k <= n), choose k distinct numbers from the set {1,2,...,n}.
Implement the output for one of the following modes (or both if required):
Combination (C): choose k numbers where order does not matter. Output all combinations.
Permutation of length k (P): choose k numbers where order matters. Output all length-k permutations.
Input
One line with three fields:
mode: a string, either C or P
n: positive integer
k: positive integer
Example: C 4 2
Output
Print all results, one per line, elements separated by spaces.
For C: print each combination in increasing order.
For P: print each permutation.
Output must be in lexicographic order.
Constraints
1 <= n <= 10
1 <= k <= n
Examples
Input: C 4 2 Output:
1 2
1 3
1 4
2 3
2 4
3 4
Input: P 3 2 Output:
1 2
1 3
2 1
2 3
3 1
3 2
Example
Input
C 4 2
Output
1 2
1 3
1 4
2 3
2 4
3 4