Hdu 5311 Hidden String (Bestcoder 1st Anniversary ($)) (Deep Search)

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=5311

Hidden String

Time limit:2000/1000 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): 1499 Accepted Submission (s): 534


Problem Descriptiontoday is the 1st anniversary of Bestcoder. Soda, the contest manager, gets a stringsof lengthN. He wants to find three nonoverlapping substringss[l1.. r1] ,s[l2.. r2] ,s[l3.. r3] that:

1.1≤L1≤r 1<l2≤r2 <l3≤r3 ≤n

2. The concatenation ofs[l1.. r1] ,s[l2.. r2] , s[l3.. r3] Is "Anniversary".

Inputthere is multiple test cases. The first line of input contains an integerT(1≤T≤) , indicating the number of test cases. For each test case:

There ' s a line containing a strings (1≤| S| ≤) consisting of lowercase 中文版 letters.

Outputfor each test case, output "YES" (without the quotes) if Soda can find such thress substrings, otherwise output "NO" (without the quotes).

Sample Input2annivddfdersewwefarynniversarya

Sample Outputyesno

Sourcebestcoder 1st Anniversary ($)

Title: Give two strings s,str[] = "Anniversary";

Divide str into three parts and ask whether these three parts can be found in s

#include <stdio.h>#include<math.h>#include<string.h>#include<stdlib.h>#defineN 110using namespacestd;intLen;CharS[n], str[] ="Anniversary";BOOLDFS (intDintL1,intL2)//D represents the level of the search, L1 means starting at the L1 position of S, and L2 indicates that Str starts at the L2 position and compares them{    intI, a, b; if(L2 = = One)        return true;//The complete sequence of str is searched, and the previous search level is no greater than 3    if(D >3)        return false;//returns False if the search level is greater than 3     for(i = L1; i < Len; i++) {a= i;//indicates starting at position a of sb = L2;//starting at the B position of str        if(S[i] = =STR[L2]) {             while(S[a] = = Str[b] && A < Len && B < One) {a++; b++; }            if(DFS (d +1, A, b)) return true; }    }    return false;}intMain () {intT; scanf ("%d", &t);  while(t--) {scanf ("%s", s); Len=strlen (s); if(DFS (1,0,0)) printf ("yes\n"); Elseprintf ("no\n"); }    return 0;}

Hdu 5311 Hidden String (Bestcoder 1st Anniversary ($)) (Deep Search)

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.