The value itself suggests a block length . Using that , you can try two roles for :
• 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 means the empty prefix.
• You start from prefix .
• You make jumps according to valid blocks.
• If you can reach prefix , then the answer is YES, otherwise NO. That is exactly what you will represent with dynamic programming.