Title Description
If a string contains two contiguous repeating substrings, it is called an "easy string", and the other strings are called "difficult strings". For example, BB,ABCDACABCAB,ABCDABCD are easy strings, and D,dc,abdab,cbabcbad are difficult strings.
Input
Enter positive integers n and L.
Output
The output consists of a string of the first L strings, a dictionary order K small difficult string. For example, when L=3, the first 7 difficult strings were a,ab,aba,abac,abaca,abacab,abacaba. Enter a guaranteed answer of no more than 80 characters.
Sample input
7 330 3
Sample output
Abacabaabacabcacbabcabacabcacbacaba
Success on the small white knocked once, but the egg, do not know the problem.
Difficult string # include <iostream> #include <string.h> #include <stdio.h>using namespace Std;int N, s[1001], L, Cnt;int DFS (int cur) { if (cnt + = = N) { for (int i=0; i<cur; i++) printf ("%c", ' A ' +s[i]); printf ("\ n"); return 0; } for (int i=0; i<l; i++) { S[cur] = i; int OK = 1; for (int j=1; j*2<=cur+1; j + +) { int e = 1; for (int k=0; k<j; k++) if (s[cur-k]! = S[cur-k-j]) { e = 0; break; } if (e) { OK = 0; break; } } if (OK) if (! DFS (cur+1)) return 0; } return 1;} int main () {while (~scanf ("%d%d", &n, &l)) { cnt = 0; Memset (s,0,sizeof (s)); DFS (0); } return 0;}
ACM Topic ———— Difficult string