The main topic: there is a string, the string is composed of 0, 1 and *, * can be changed to 0 can also be changed to 1, the character required to change the string can only be 0 or 1.
This string is now given, requiring that no three consecutive identical substrings should be present in the changed string, and that the maximum number of strings that can be changed to match the rules
Thinking: Because only 0 and 1, and only 30 bits, so you can use a positive number to represent the state. DFS brute force enumeration, edge enumeration edge judgment, see if current matches
#include <cstdio>#include <cstring>using namespace Std;#define MAXNintNChar Str[Maxn];bool Judge (intSintL) {int MoD= (1<< L)-1;intFirst = (S &MoD); s = (S & (~MoD)) >> L;intSecond = (S &MoD); s = (S & (~MoD)) >> L;if(first = = Second && second = = s)return true;return false;}intDfsintSintcur) {intS0 = s; for(inti =0; I <= cur-3; i++) {if(((cur-i)%3==0) && judge (S0, (cur-i)/3))return 0; S0 = (S0 & (~1)) >>1; }if(cur = = N)return 1;if(Str[cur] = =' 0 ')returnDFS (s, cur +1);if(Str[cur] = =' 1 ')returnDFS (s ^ (1<< cur), cur +1);returnDFS (s, cur +1) + DFS (s ^ (1<< cur), cur +1);}intMain () {intCAS =1; while(SCANF ("%d", &n)! = EOF && N) {scanf ('%s ',Str); printf"Case%d:%d\n", cas++, DFS (0,0)); }return 0;}
UVA-11127 triple-free Binary Strings Dfs