2.3.1 LONGEST PREFIX

Source: Internet
Author: User
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

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.