String / type sequence DP (a)

Topic: P1279 string distance

\ (\ Text {konjac way of seeking the DP} \)

This question reminds me of adding several multiplication sign that the product the biggest problem in a numeric string. I began to consider the former \ (i \) characters to insert \ (j \) minimum distance of characters. Later, I found that I will not be transferred (tears). So I'm going step by step, began to find its secrets from the analysis.

Thinking

This question is observed then the value of minimum required matching characters difference. As compared to the insertion space in the string, as it is specified which character and which character pairs, such that the minimum distance. So I think the P1140 similar genes , if we set \ (f [i] [j] \) represents A string of characters before i and j B string of characters before the minimum distance decision-making can bring , it will be more simple?

According to the idea usual DP then, we should consider it a sub-problem is the assumption that we. Have already obtained the minimum distance , then how should we do it on this topic, we have three decisions?:

  1. Let \ (A_i \) and \ (B_j \) pair
  2. Let \ (A_i \) and spaces paired, the \ (B_i \) left behind
  3. Let \ (B_i \) and spaces paired, the \ (A_i \) left behind

We find these three decisions, then we consider the possibility of transfer, how transfer.

If we let \ (A_i \) and \ (B_j \) pair, then it is from \ (f [i-1] [j-1] \) transferred over, then add the absolute value of the difference of the two.

If we let \ (A_i \) paired with spaces, is to ask \ (B_j \) already before the A paired characters or spaces, so as to ensure a corresponding bit before i before j bits, and then adding a constant K

Similarly, if you let \ (B_i \) paired with a space, requires \ (A_i \) paired with something before B, then adding a constant K.

So, we moved to \ (f [i] [j ] \) , the need to obtain the minimum value from the following three decisions:
\ [1.f [i-1] [J-1] + | A [ i] -B [j] | ( \ text { bunches pairing}) \]
\ [2.f [. 1-I] [J] + K (\ text {A} pairing and spacing) \]
\ [3. f [i] [j-1 ] + K (\ text {B } paired with spaces) \]
then another point is that we obviously need to initialize, and nothing can not match. so we let the two strings are pairing spaces Finally, our goal is to \ (f [lenth (a) ] [length (B)] \)

There are many similar problems, and resume it later to explain

Guess you like

Origin www.cnblogs.com/i-cookie/p/11583787.html