1081. Binary Lexicographic Sequence
Time limit: 0.5 second
Memory limit: 64 MB
Consider all the sequences with length (0 < N < 44), containing only the elements 0 and 1, and no two ones are adjacent (110 is not a valid sequence of length 3, 0101 is a valid sequence of length 4). Write a program which finds the sequence, which is on K-th place (0 < K < 109) in the lexicographically sorted in ascending order collection of the described sequences.
Input
The first line of input contains two positive integers N and K.
Output
Write the found sequence or −1 if the number K is larger then the number of valid sequences.
Sample
Problem Author: Emil Kelevedzhiev
Problem Source: Winter Mathematical Festival Varna '2001 Informatics Tournament
Difficulty: 256 Printable version Submit solution Discussion (24)
|
求字典序下,第k个长度为n的合法字符串(合法字符串满足:只有0和1,且不能有两个1相邻)
打表会发现,长度为n的合法序列一共有Fibonacci[n]个。其中有Fibonacci[n - 1]个是由0开头的(也就是长度为n-1前面的补0),剩下的是以1开头 的。
#include
#include