Dynamic Programming21 sections · 916 units
Open in Course

Codeforces 1741E Sending a Sequence - Problem Statement

Understand the block cutting problem where each block has a length marker

Sending a Sequence Over the Network, Idea and Intuition This is your first DP problem where dp[i] represents whether a prefix is valid of the array instead of values or indices in the usual sense.

You are given a sequence b1,b2,,bn.b_1, b_2, \dots, b_n. You want to cut it into blocks. Each block must look like one of these two patterns:

1.1. Length on the left [L,x1,x2,,xL][L, x_1, x_2, \dots, x_L]

2.2. Length on the right [x1,x2,,xL,L][x_1, x_2, \dots, x_L, L]

So every block contains exactly one number LL and exactly LL other numbers. The whole array must be covered by such blocks, without overlapping and without leaving anything out.

Now that you understand what the problem is asking, let us think about how to approach it.