#P2727. Find the i-th Valid Binary String
Find the i-th Valid Binary String
Find the i-th Valid Binary String
We consider all binary strings of fixed length \( N \) that have at most \( L \) ones (i.e., the number of ones is \( \leq L \)). These strings are sorted in increasing lexicographical order. Your task is to output the \( i \)-th smallest string among these valid strings. It is guaranteed that such a string exists.
For example, for the binary string 100101
, we have \( N=6 \) and the number of ones is 3.
inputFormat
The input consists of three space-separated integers:
- \( N \) (\( 1 \leq N \leq 50 \)): the length of the binary strings.
- \( L \) (\( 0 \leq L \leq N \)): the maximum allowed number of ones in the string.
- \( i \) (\( 1 \leq i \leq \text{number of valid strings} \)): the 1-indexed position of the string in the sorted order.
outputFormat
Output the \( i \)-th smallest binary string (of length \( N \)) that has at most \( L \) ones.
sample
6 3 1
000000