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

Автор Hd7, история, 5 лет назад, По-английски

The problem VK2012 B — File List.
I solved it by using greedy, but this problem was tagged dp and the editorial instructed dp approach such that:

is [i] — can we cut the prefix of length i .

Initially, is [0] = 1, the remaining zeros.

Now iterate over i in ascending order and if is [i] = 1, try to make the transition to i  + 1 .. i  + 12

I still can't solve it by DP, could you give me a more detailed explanation to solve this problem using DP? Thanks in advance!

Теги #dp
  • Проголосовать: нравится
  • -9
  • Проголосовать: не нравится

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

What wrong with you, all of down-vote lover. You can consider what wrong with my question here.

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    You need to be atleast candidate master to keep any hopes for getting upvotes and good responses. First become that and ask the same question again. See the difference yourself

»
5 лет назад, # |
Rev. 4   Проголосовать: нравится +1 Проголосовать: не нравится

If we knew the fact that we can divide the prefix ending at $$$i$$$ ($$$is[i]=true$$$), so we have complete partition ending at $$$i$$$, and we can now try to make the next part, which starts at $$$i+1$$$ and ends at either one of the positions $$$i+1$$$, $$$i+2$$$, $$$\dots$$$, $$$i+12$$$, inclusive.

Why $$$+12$$$? Because the longest valid file name possible is $$$8+1+3=12$$$: $$$8$$$ for the first part (of the file name), $$$1$$$ for the period and $$$3$$$ for the second part.

So, at each position $$$i$$$ where $$$is[i]=true$$$, we will try all the substrings $$$A[i+1\dots i+j]$$$ (where $$$1<=j<=12$$$), and at each $$$j$$$, we see if the substring is a valid file name (depending on the conditions in the statement), if yes, we set $$$is[i+j]=true$$$, and here we can keep tracking for an answer by define an array $$$par[]$$$, and when we set $$$is[i+j]=true$$$, we set $$$par[i+j]=i$$$.

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Does $$$is[i+1], is[i+2]$$$ is always false, because with one or two characters, we can't construct a valid file name?

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Not exactly, but if $$$is[i]=true$$$ you cannot update the values at $$$i+1$$$ and $$$i+2$$$ because of the reason you mentioned, but $$$is[i+1]$$$ and $$$is[i+2]$$$ can be $$$true$$$ because of a valid position before $$$i$$$.

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

My solution for this problem using DP. I implement it quite hard, are there any ways to implement it much better mine?