题目链接:
题目描述 Description
输出仅有0和1组成的长度为n的字符串,并且其中不能含有3个连续的相同子串。
输入描述 Input Description
输入文件只有一行一个整数n,表示有0和1组成的字符串的长度。0<=n<=30。
输出描述 Output Description
输出文件只有一行一个整数,表示所有满足条件的字符串的个数。
样例输入 Sample Input
1
样例输出 Sample Output
2
思路:
dfs水题,没加剪枝都能过,数据太弱
/**************************************************
> File Name: 1065.cpp
> Author: dulun
> Mail: dulun@xiyoulinux.org
> Created Time: 2016年03月23日 星期三 22时46分51秒
*****************************************/
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define LL long long
using namespace std;
const int N = 50086;
int n;
bool a[45];
bool v[45];
int ans = 0;
void dfs(int cur)
{
if(cur == n && a[n-1]+a[n-2]+a[n-3] != 3 || a[n-1]+a[n-2]+a[n-3] != 0)
{
ans++;
return;
}
a[cur] = 1;
dfs(cur+1);
a[cur] = 0;
dfs(cur+1);
}
int main()
{
cin>>n;
dfs(0);
cout<<ans;
return 0;
}


697

被折叠的 条评论
为什么被折叠?



