Difficult string (search)

Source: Internet
Author: User

If a string contains two contiguous repeating strings, it becomes an easy string, otherwise difficult strings, such as difficult string A,ab,abac,abaca,...

Input n,l, the output is composed of the first L characters, the dictionary sequence K small difficult string.

The idea is similar to the N queen problem, in determining if a repeating string exists simply to determine the suffix of the current string, not all substrings.

1#include <iostream>2#include <cstdio>3 using namespacestd;4 intl,n,s;5 BOOLflag=0;6 Charch[10000];7 intJudgeints)8 {9     inti=s,j=s,k=1, X;Ten     if(s<=1) One         return 1; A     Else -     { -          while(k<=s/2) the         { -             intCount=0; -j=j-1; -              for(x=0; x<k;x++) +                 if(ch[i-x]==ch[j-x]) -count++; +             if(count==k) A                 return 0; atk++; -         } -     } -     return 1; - } - voidDfsints) in { -     inti,j,k; to     if(flag) +         return; -     if(s== (n+1)) the     { *          for(i=1; i<=n;i++) $cout<<Ch[i];Panax Notoginsengcout<<Endl; -flag=1; the         return; +     } A      for(i=0; i<l;i++) the     { +ch[s]='A'+i; -         if(judge (s)) $         { $s++; - Dfs (s); -         } the     } - }Wuyi intMain () the { -     inti,j,k; Wu      while(cin>>n>>L) -     { Abouts=1; $flag=0; - Dfs (s); -     } -     return 0; A}

Difficult string (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.