Ultraviolet A 1625-color length (l c s in DP problem solution deformation)

Source: Internet
Author: User

LCS is a dynamic planning of linear structures. It should be a very simple type of dynamic planning.

The longest common subsequence problem. Once the state is identified, it is very easy to find the state transition equation. But for this question, one of the difficulties is that it is difficult to think about how to define the State.

As a cainiao, I think this question is very complicated.

First of all, I cannot think of adding 1 to all the letters that have not reached the end point in each step, and the effect is the same as that of searching for the start and end points.

Even if it is not a subject of motion planning, I cannot think of such a question at all and will solve it with motion planning.

Again, I can't think of the State to define "set d [I] [J] to indicate that the two sequences have taken out I and j elements respectively ". The value represents the minimum L value of the current state.

I can hardly believe that I can process the CNT [I] [J] array in the early stage. In fact, I have already completed most of it, however, it seems that I have no confidence in the O (N ^ 3) method, so I gave up.

I don't know if it's because of the fear of complicated processing. After the methods are clearly defined, there is still no clear idea in the code writing process, which leads to poor handling in many aspects during the problem solving process, it has had a huge impact on the final result and caused great difficulties for the final Debug. It has wasted a lot of energy and time, and has done a lot of useless work. Therefore, we must reflect on it.

At last, although the state transition equation is clearly defined, the logic of boundary processing is confusing. It's just a guess! Ask yourself what the status is? Should you guess? You don't even have a mind. You guess, why don't you move the bricks? You guess P? Can't you just calm down and seriously consider the convenient status? I think you can clearly mark the boundary. Why don't you calm down and think about it? Reflection is required!

The environment is too messy, and the discussions around me make me impetuous. However, you shouldn't be impetuous about any questions.

# Include <cstdio> # include <string> # include <cstring> # include <iostream> # include <algorithm> using namespace STD; # define INF 0x6fffffffconst int maxn = 5010; char S1 [maxn], S2 [maxn]; struct color {int ST1, end1; int st2, end2; int OK;} CO [30]; int CNT [maxn] [maxn]; int d [maxn] [maxn]; int main () {int t; scanf ("% d", & T ); while (t --) {scanf ("% S % s", S1, S2); int len1 = strlen (S1); int len2 = strlen (S2 ); for (INT I = 0; I <30; I ++) {Co [I]. OK = 1; CO [I]. ST1 = Co [I]. st2 = inf; CO [I]. end1 = Co [I]. end2 =-INF;} For (INT I = 0; I <len1; I ++) {int temp = S1 [I]-'A '; if (CO [temp]. OK = 1) {Co [temp]. OK = 0; CO [temp]. ST1 = I;} CO [temp]. end1 = I ;}for (INT I = 0; I <30; I ++) {Co [I]. OK = 1 ;}for (INT I = 0; I <len2; I ++) {int temp = S2 [I]-'A'; If (CO [temp]. OK = 1) {Co [temp]. OK = 0; CO [temp]. st2 = I;} CO [temp]. end2 = I ;}for (INT I = 0; I <= len1; I ++) {for (Int J = 0; j <= len2; j ++) {int CNT _ = 0; For (int K = 0; k <26; k ++) {If (CO [K]. ST1 = inf & Co [K]. st2 = inf) continue; If (CO [K]. ST1> I-1 & Co [K]. st2> J-1) // note that it is a I-1; (verified by reasoning, correct) continue; If (CO [K]. end1 <= I-1 & Co [K]. end2 <= J-1) // is less than or equal to the I-1; (verified, correct) continue; CNT _ ++;} CNT [I] [J] = CNT _;}} d [len1] [len2] = 0; For (INT I = len2-1; I> = 0; I --) {d [len1] [I] = d [len1] [I + 1] + CNT [len1] [I] ;}for (INT I = len1-1; I> = 0; I --) {d [I] [len2] = d [I + 1] [len2] + CNT [I] [len2];} For (INT I = len1-1; i> = 0; I --) {for (Int J = len2-1; j> = 0; j --) {d [I] [J] = min (d [I + 1] [J], d [I] [J + 1]) + CNT [I] [J] ;}} printf ("% d \ n", d [0] [0]) ;}return 0 ;}

In the future, len1 and len2 will not be used in the recurrence process. If you look at it next door, you will not be happy !!!!! Unhappy! Success !!!!

I have been doing this for a long time. I should calm down and have my own attitude when encountering complicated questions and questions that cannot be solved. It cannot solve anything or help. The most important thing is to take it seriously.

I 'd rather not do it, nor do it together.

Again, we should improve our affirmation of our own abilities. Since we have ideas and ideas, we should encourage ourselves to finish writing them ~ Even if the timeout is incorrect, it is also a kind of exercise for your own code capabilities and mind, which helps improve your code capabilities and enhance your belief that you dare to start with complicated questions. Not afraid of trouble, not afraid of difficulties. Lack of a spirit



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.