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

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

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
  • Проголосовать: не нравится

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

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

»
7 лет назад, скрыть # |
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 \lt =j \lt =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$$$.

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

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