Title Description:
Any combination of the first L characters in the given a-Z;
Hard string for the combined resulting string that does not contain adjacent repeating strings
Solving nth hard strings by dictionary order
The thinking of solving problems: Backtracking method can
#include <cstring> #include <cstdio>using namespace std;int n,l;char ans[82];bool check (int len) {int flag=f Alse; for (int t=len-1; t>= (len+1)/2; t--) {int i=t; int J=len; while (j>t) {if (ans[i]!=ans[j]), break; I--, j--; } if (j==t) {flag=true; Break }} return flag;} int t;bool dfs (int len) {if (t==n) return true; if (len==80) return false; for (int i=0; i<l; i++) {ans[len+1]= ' A ' +i; if (!check (len+1)) {t++; if (Dfs (len+1)) return true; } ans[len+1]= ' + '; } return false;} int main () {while (scanf ("%d%d", &n,&l) ==2&& (n!=0| | l!=0)) {memset (ans,0,sizeof (ans)); t=0; DFS (0); int Len=strlen (ans+1); for (int i=1; i<=len; i++) {printf ("%c", Ans[i]); if (i%64==0&&i<len) {printf ("\ n"); Continue } if (I%4==0&&i<len) printf (""); } printf ("\ n"); printf ("%d\n", Len); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
hdu1627 Krypton Factor