Codevs 1065 01 Stringtime limit: 1 sspace limit: 128000 KBtitle level: Golden GoldTitle Description
Description
The output is only a string of length n of 0 and 1, and it cannot contain 3 contiguous strings of the same substring.
Enter a description
Input Description
The input file has only one line of integer n, representing the length of the string consisting of 0 and 1. 0<=n<=30.
Output description
Output Description
The output file has only one line of integers, representing the number of strings that satisfy the criteria.
Sample input
Sample Input
1
Sample output
Sample Output
2
1 /*dfs+ Violence Test2 */3#include <iostream>4 using namespacestd;5#include <cstring>6#include <cstdio>7 Charans[ *];8 intn,sum=0;9 BOOLCheckintL1,intR1,intL2,intR2)Ten { One while(l1<=r1&&l2<=R2) A { - if(Ans[l1]!=ans[l2])return false; -l1++;l2++; the } - return true; - } - voidDfsintk) + { - if(k==n+1) + { Asum++; at return; - } - for(intI=0; i<=1;++i) - { -ans[k]=i+'0'; - BOOLflag=true; in for(intj=1; j<=k/3;++j) - if(Check (k-j+1, k,k-j-j+1, k-j) &&check (k-j+1, k,k-j-j-j+1, k-j-j)) to{flag=false; + Break; - } the if(flag) * { $DFS (k +1);Panax Notoginsengans[k]=0; - } the Else Continue; + } A } the intMain () + { -scanf"%d",&n); $ if(n==0) $ { -printf"0"); - return 0; the } -Dfs1);Wuyiprintf"%d\n", sum); the return 0; -}
Depth-First search Codevs 1065 01 Strings