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

Автор Destopia, история, 3 года назад, По-английски

Given N strings N <= 1000. The task is to choose a subsequence such that the concatenation of the chosen elements gives the maximum lexicographical string. For example N = 3, ["ab", "ac", "b"] answer = "b", N = 2 ["z", "za"] answer is "zza". How to solve this problem?

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

»
3 года назад, # |
  Проголосовать: нравится +55 Проголосовать: не нравится

Hi stuck, I'm Ivan!

You should solve it backwards greedily. If $$$s$$$ is the solution for the last $$$k$$$ strings, then, for the last $$$k+1$$$ it's either $$$ps$$$ or $$$s$$$, where $$$p$$$ is the $$$k+1$$$-st string from the end.

»
3 года назад, # |
  Проголосовать: нравится +41 Проголосовать: не нравится

Hmm, CornHub's interface is looking rather weird today

»
3 года назад, # |
  Проголосовать: нравится +47 Проголосовать: не нравится

What are you doing step-coder??

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

How is the answer for N=3, {"b", "ab", "ac"} "b", shouldn't it be "bacab". This is a greedy problem using sorting!