QUESTION: (such as Question)
Input and output: (such as the question)
Solution:
1. Simple dynamic planning.
2. Tangle of boundary processing. It is not recommended to use dp [I] to indicate whether this method can be obtained by I characters before s. Using this method to store strings is troublesome. In addition, if the storage does not process the boundary, it will be very troublesome ...... (I used this method first. As a result, WA is performed four times. If the length is set to 0 and the length is set to 1 multiple times, it cannot be distinguished and I finally gave up)
Core code:
Lens = s. length (); for (I = 0; I <lens; I ++) {for (j = 0; j <cntp; j ++) {flag = false; len = p [j]. length (); if (I + len> lens) // if this string is added beyond the length of s, the condition continue is not met; for (k = 0; k <len; k ++) if (s [I + k]! = P [j] [k]) // a different character does not meet the condition {flag = true; break;} if (flag = false & len + I> maxn) // the maximum value for conditional update maxn = len + I;} if (I + 1> maxn) // The end condition break ;}
2.3.1 LONGEST PREFIX