Depth-First search Codevs 1065 01 Strings

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.