Hi everyone! Recently I have been solving some classic interval DP problems, and came across some neat problems. Most of these problems have relatively simple recurrence relations, but the straightforward solutions will not pass in complexity, hence requires an observation to reduce the complexity (generally by reducing the number of states by some pre-computation). Most of the problems are from CF, and they already have editorials. But I will still write my own tutorials to illustrate my points.
Prerequisites : Introductory interval DP such as Longest Increasing Subsequence, Longest Common Subsequence.
You are given an array of $$$a_1,a_2,\dots,a_n$$$ length $$$n \ (n \leq 500, 1 \leq a_i \leq 1000).$$$ You can perform the following operation any number of times:
- Choose a pair of two neighboring equal elements $$$a_i=a_{i+1}$$$ (if there is at least one such pair).
- Replace them by one element with value $$$a_i + 1$$$. After each such operation, the length of the array will decrease by one (and elements are renumerated accordingly). What is the minimum possible length of the array a you can get?
Given two strings $$$s$$$ and $$$t$$$ ($$$|t| \leq |s| \leq 400$$$, we need to tell whether two disjoint subsequences of $$$s$$$ can be concatenated to create t.
Given a string $$$s$$$ and another string $$$p$$$, you need to find maximum number of non-overlapping substrings of $$$s$$$ that are equal to $$$p$$$ after deleting $$$x$$$ characters from $$$s$$$ for all $$$x \in [0, |s|]$$$. ($$$|s| \leq 2000, |p| \leq 500$$$).
1337E - Kaavi and Magic Spell You are given a string $$$s$$$ of length $$$n$$$ and another string $$$t$$$ of length $$$m$$$ (
Unable to parse markup [type=CF_MATHJAX]
. In one operation, you can take the first character of $$$s$$$ and either prepend or append it to $$$a$$$ and erase it from $$$s$$$. After at-most $$$n$$$ operations, in how many different sequence of operations can you create $$$a$$$ such that it has $$$t$$$ as a prefix (modulo $$$998244353$$$).