您的位置:首页 > 其它

codevs 1065 01字符串 题解报告

2016-10-30 19:10 459 查看
0.0

0.0

0.0

题目描述 Description

输出仅有0和1组成的长度为n的字符串,并且其中不能含有3个连续的相同子串。

输入描述 Input Description

输入文件只有一行一个整数n,表示有0和1组成的字符串的长度。0<=n<=30。

输出描述 Output Description

输出文件只有一行一个整数,表示所有满足条件的字符串的个数。

样例输入 Sample Input

1

样例输出 Sample Output

2

数据范围及提示 Data Size & Hint

0.0

0.0

0.0

说实话我 没 看 懂 题!!

问了他们做过的,

才知道。

只要字符串里没有 000 111 就好了。

嗯,

直接dfs

记录上一个和上上个是什么就行。

0.0.0

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#include<iomanip>
#include<deque>
#define INF 1000000000
#define fi first
#define se second
#define N 100005
#define P 1000000007
#define debug(x) cerr<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
int n,m;
inline int get_num()
{
int num = 0;
char c;
bool flag = false;
while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
if (c == '-') flag = true;
else num = c - '0';
while (isdigit(c = getchar()))
num = num * 10 + c - '0';
return (flag ? -1 : 1) * num;
}
void dfs(int x,int l,int ll)
{
if(x==n)
{
m++;
return;
}
if(l==ll)
{
if(ll==1)
{
dfs(x+1,2,1);
return;
}
if(ll==2)
{
dfs(x+1,1,2);
return;
}
}
dfs(x+1,1,l);
dfs(x+1,2,l);
}
int main()
{
cin>>n;
dfs(0,0,0);
cout<<m;
}


噫/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  noip dfs codevs