Блог пользователя T_C_D

Автор T_C_D, история, 22 месяца назад, По-английски

Suppose i have a dictionary of an alphabet D (|D|>1) and i have an integer n (n between 1 and 1e18). I want to find the nth lexicographical string in this dictionary. How can I solve this problem?

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Suppose there are $$$x$$$ distinct characters, then we can simply transform $$$n$$$ into base $$$x$$$ to get the answer.

»
20 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

walk on A-ary trie by holding subtree size. Where A is Alphabet size

»
20 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

If this problem is about finding the nth lexicographical string, then the answer is character A n times, where A is the smallest lexicographical. I think they intended for the sequence to be sorted by length, and only then lexicographically. Then you can first find its length, denote it as L, then find nth lexicographical string of length L (n will be different after canceling out every string with size < L). I can share the code if you want