6

Some Interval DP Problems and State Reduction

 1 year ago
source link: http://codeforces.com/blog/entry/108850
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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.

1312E - Array Shrinking

You are given an array of length You can perform the following operation any number of times:

  • Choose a pair of two neighboring equal elements (if there is at least one such pair).
  • Replace them by one element with value . 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?
Solution
Code

1303E - Erase Subsequences

Given two strings and (, we need to tell whether two disjoint subsequences of can be concatenated to create t.

Hint
Solution
Code

476E - Dreamoon and Strings

Given a string and another string , you need to find maximum number of non-overlapping substrings of that are equal to after deleting characters from for all . ().

Solution
Code

1337E - Kaavi and Magic Spell

You are given a string of length and another string of length (). Initially you have an empty string . In one operation, you can take the first character of and either prepend or append it to and erase it from . After at-most operations, in how many different sequence of operations can you create such that it has as a prefix (modulo ).

Hint
Solutions
Code

1025D - Recovering BST

Given a sorted array of length (), you need to tell if it is possible to create a binary search tree of that array such that no two adjacent nodes are coprime.

Hint
Solution
Code

I am done for today. I hope this benefits whoever is reading. Also feel free to correct any mistakes you might have found.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK