Pro.ID21075 TitleStringer Title链接http://10.20.2.8/oj/exercise/problem?problem_id=21075 AC0 Submit899 Ratio0.00% 时间&空间限制描述Imagine a list of strings that are all built from the first N letters of the alphabet, which all have a predetermined number of a’s, a predetermined (but possibly different) number of b’s, and so on.
Imagine that it’s sorted in alphabetical order, and numbered, starting at 0. What’s the Kth string in the list?
For example, look at all strings of a’s and b’s (N=2) with 2 a’s and 3 b’s:
If K=5, then the Kth string in the list would be babab. 输入Input will consist of multiple datasets. Each dataset consists of two lines.
On the first line are two integers, N (1 <= N <= 20) and K (0 <= K < m), where N is the number of letters of the alphabet used, K is the index of the list element that should be found, and m (not given explicitly in the input) denotes the number of strings make up the list.
m, the number of strings in the list may be very, very large (too large to permit generating the whole list), but the input will be chosen so that m and K will each fit in a 32 bit integer.
On the second line will be N non-negative integers, which represent the number of a’s, the number of b’s and so on. The sum of these integers is guaranteed to be at least 1 and no greater than 50.
End of input is indicated by a line with two zeros. 输出Description Imagine a list of strings that are all built from the first N letters of the alphabet, which all have a predetermined number of a’s, a predetermined (but possibly different) number of b’s, and so on.
Imagine that it’s sorted in alphabetical order, and numbered, starting at 0. What’s the Kth string in the list?
For example, look at all strings of a’s and b’s (N=2) with 2 a’s and 3 b’s:
If K=5, then the Kth string in the list would be babab. Input Input will consist of multiple datasets. Each dataset consists of two lines.
On the first line are two integers, N (1 <= N <= 20) and K (0 <= K < m), where N is the number of letters of the alphabet used, K is the index of the list element that should be found, and m (not given explicitly in the input) denotes the number of strings make up the list.
m, the number of strings in the list may be very, very large (too large to permit generating the whole list), but the input will be chosen so that m and K will each fit in a 32 bit integer.
On the second line will be N non-negative integers, which represent the number of a’s, the number of b’s and so on. The sum of these integers is guaranteed to be at least 1 and no greater than 50.
End of input is indicated by a line with two zeros. Output Output each answer string on its own line. Do not print any extra white space. Do not print any blank lines between answers. Sample Input 2 5
2 3
3 0
2 3 1
0 0 Sample Output babab
aabbbc Source 样例输入2 5
2 3
3 0
2 3 1
0 0 样例输出babab
aabbbc 作者 |