HDU-2087-cut fabric strips KMP

Source: Internet
Author: User
Flower scissors

Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 2819 accepted submission (s): 1884

Problem description

There are some patterns in a fabric, and some other small ornaments that can be used directly. For the given flower cloth and small ornaments, how many small ornaments can be cut out from the flower cloth as much as possible?

Input

The input contains some data, such as a pair of fabric and decoration. The fabric is represented by visible ASCII characters and the number of visible ASCII characters, how many patterns are there in the cloth pattern. The length of the pattern and ornament cannot exceed 1000 characters. If the # character is met, the job will not be started.

Output

The maximum number of small ornaments that can be cut out from the pattern cloth. If none of the ornaments exist, 0 will be output honestly, with a line break between each result.

Sample inputabcde A3
Aaaaaa
#

Sample output0
3. In the application of KMP, a substring is quickly matched in a parent string. The change made to this question is that in the matching process, when the condition is met, the match continues instead of exiting, check how many substrings can be produced in the parent string. Code As follows:
#include 
  
    # include 
   
     char ob [1005], sub [1005]; int next [1005], lob, LSUB; void exgetnext (char * t, int * Next) {int K = 1, j = 0; while (k 
    
   
  

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.