#K46382. Identification Code Generator
Identification Code Generator
Identification Code Generator
You are given n participants. For each participant, a required code length and a set of available characters are provided. The task is to generate all possible identification codes by selecting characters from the participant’s character set. For each participant, first sort the character set in lexicographical order, then generate all combinations of the given length using the sorted characters.
Formally, for a participant with a character set \(S\) (after sorting) and a required code length \(L\), you are to generate all combinations \(\{s_1, s_2, \dots, s_L\}\) such that \(s_1 < s_2 < \dots < s_L\). Output each participant's codes in one line, with individual codes separated by a space.
Note: It is guaranteed that \(1 \leq L \leq |S|\), and the available characters in \(S\) are all distinct letters.
inputFormat
The first line contains an integer \(n\), which denotes the number of participants. Each of the following \(n\) lines contains an integer \(L\) (the required code length) and a string \(S\) (the set of available characters), separated by space.
Example:
2 3 abcde 2 wxyz
outputFormat
For each participant, output a single line containing all valid identification codes, separated by a space. The codes for each participant should be printed in lexicographical order.
Example Output:
abc abd abe acd ace ade bcd bce bde cde wx wy wz xy xz yz## sample
1
1 a
a
</p>