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
代码:
噫/
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; }
噫/
相关文章推荐
- Codevs 1065 01字符串
- CODE[VS] 1065 01字符串
- codevs 1009 产生数 题解报告
- codevs 1045 回文数 题解报告
- codevs 1019 集合论与图论 题解报告
- codevs 1060 搞笑世界杯 题解报告
- codevs 3301 Square words 题解报告
- codevs 1961 躲避大龙 题解报告
- codevs 1058 合唱队形 题解报告
- codevs 2488 绿豆蛙的归宿 题解报告
- codevs 2618 核电站问题 题解报告
- codevs 2833 奇怪的梦境 题解报告
- codevs 1507 酒厂选址 题解报告
- codevs 1036 商务旅行 题解报告
- 【codevs1040】【01NOIPTG】统计单词个数,字符串的划分DP
- codevs 1228 苹果树 题解报告
- Codevs1128苹果树题解
- Code[VS] 1021 玛丽卡 题解
- [codevs3160]最长公共子串解题报告|后缀自动机
- 【基础练习】【拓扑排序】codevs3294 车站分级题解