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)