meaning of a title
Given two objects of length\(n\) strings\(S, T\)to find the minimum number of operations that should be performed in order to make the\(S = T\)。
A single operation is defined as: for\(i = 1, 2, .. n\)Decree No.\(i\) bit is an operationempressthirteenth meeting of the Conference of the Parties to the Convention on Biological Diversity (CBD)\(i - 1\) bit or operationaheadthirteenth meeting of the Conference of the Parties to the Convention on Biological Diversity (CBD)\(i\) Bit. (\(i = 1\) (when only the second)
analyze
Race time thought of a fake greed and thought of setting up a\(pos_i\) In order to be in the answer\(T_i\) attributable\(S_{pos_i}\) Contributions that can be found\(\forall 1\le i < n, pos_i\le pos_{i + 1}\)And if\(i < j\) I'm sure you'll do it first.\(j\)。
This line of thought seems fine, but the conclusion that follows is wrong, and the reason I thought so at the time was that if the\(i\) Finish first.\(j\) There would be no more, but is it really true that one can\(pos_i\) first operate on\(pos_j - 1\),\(pos_j\) Operate to\(i + 1\) and after.
Reason for the error: It was not optimized and operations that could be done earlier were done later.
Update:Broken, this question is obviously done backwards to eliminate the aftereffects, directly greedy so aftereffects how to do. Inverted to do a good job of writing more / kel
Consider having gotten\(pos_i\)(For\(i\) Find the first one.\(j\) feasible\(s_j = t_i\) both (... and...)\(j \le pos_{i + 1}\)), equivalent to\(S = 1, 2, ... n\),\(T = pos_1, pos_2, ..., pos_n\)We found that it must be optimal to expand as far to the right as possible each time, and then leave 1 for the useful one to expand to the right.
Consider how to maintain this, first remove the useless ones, shrink the same S's together, each time from right to left, and in turn perform the process of shrinking the current interval to only the right endpoint, and expanding the right endpoint as far to the right as possible, which is good maintenance.
Consider why it is important for
- This can be done in reverse according to the greedy process
- It's already the greediest.
Consider how to maintain it, look for patterns, and find out that it is carried out\(j\) The current range after the first operation\(i\) (used form a nominal expression)\(R_i = R_{i + j} - j\)The make sth. happen\(R_j(j > n) = +\inf\) That's enough.