题解:
LRJ大法。
如何避免相邻的重复子串?每增加一个字符,从长度j(1 <= j <= len / 2)开始,检查当前串的最后 j 个字符和其前面的 j 个字符是否相同,len为当前串的长度,如果满足条件则成功生成了一个串。
# include <iostream>
# include <cstdio>
# include <cstring>
using namespace std;
int n, L;
int S[100];
int cnt;
int dfs(int pos) //返回0表示已经得到解,无须继续搜索
{
if(cnt++ == n)
{
for(int i = 0; i < pos; ++i)
{
if (i % 64 == 0 && i > 0) printf("\n");
else if (i % 4 == 0 && i > 0) printf(" ");
printf("%c", 'A' + S[i