Dynamic Programming21 sections · 916 units
Open in Course

Codeforces 1741E Sending a Sequence - From Intuition to Prefix States

From intuition to states

The value bib_i itself suggests a block length LL. Using that LL, you can try two roles for bib_i:

• It might be the length at the right end of a block.

• It might be the length at the left end of a block. Each of these cases tells you how you can jump from one prefix length to another. The whole problem becomes a reachability question on prefix positions:

• Position 00 means the empty prefix.

• You start from prefix 00.

• You make jumps according to valid blocks.

• If you can reach prefix nn, then the answer is YES, otherwise NO. That is exactly what you will represent with dynamic programming.