首页
DreamJudge
院校信息
考研初试
考研复试
保研专区
讨论区
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
Jinx_K
2026年3月13日 15:21
不连续1的子串 题解:long long
P1726
回复 0
|
赞 2
|
浏览 57
#include <iostream> #include <string> #include <cstring> using namespace std; int main() { int N; cin>>N; long long total[21]={1}; total[1]=2; total[2]=3; int x=2; if(N>2) while(x++!=N) total[x]=total[x-1]+total[x-2]; cout<<total[N]...
bro
2026年3月5日 16:53
不连续1的子串 题解:c++,是N阶楼梯上楼,不能连续上1层问题的变形
P1726
回复 0
|
赞 12
|
浏览 171
#include <bits/stdc++.h> using namespace std; long long step(int n,int str){ if(n == 1) return 1; if(str == 1) return step(n-1,0); return step(n-1,1) + step(n-1,0); } int main(){ int n; while(cin >> n){ ...
一字清若杰
2026年2月23日 14:57
不连续1的子串 题解:纯递归
P1726
回复 0
|
赞 2
|
浏览 169
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<char> str(30, '0'); int counts = 0; int N; void f(int n) { if (n > N) { counts++; &...
yauqq
2026年2月9日 10:32
不连续1的子串 题解:
P1726
回复 0
|
赞 3
|
浏览 200
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; int a[20]; a[0] = 0; a[1] = 2; a[2] = 3; for(int i=3;i<=n;i++) a[i] = a[i-1] + a[i-2]; cout << a[n] << endl; return 0; }
Yelson
2025年6月13日 17:18
不连续1的子串 题解:
P1726
回复 0
|
赞 16
|
浏览 1.9k
离散数学的东西忘了,写篇题解来增强下记忆。 记f(n)为长度为n的不含连续1的串的个数, 若末尾(从1计数,第n位)为0,则第n-1位可以是1,也可以是0,共有f(n-1)种情况; 若末尾为1,则第n-1位必然为0(不能有连续的1),此时第n-2位可以是1,也可以是0,共有f(n-2)种情况。 根据以上两种情况,得出递推公式为f(n)=f(n-1)+f(n-2),初始状态为f(1)=2,f(2)=3。 感谢Patrick老师的离散数学课:)。
jy2025
2025年3月9日 17:43
不连续1的子串 题解:找规律+动规模版
P1726
回复 0
|
赞 12
|
浏览 1.1k
#include<stdio.h> int main(){ int i,n; long long a[90]; while(scanf("%d",&n)!=EOF){ //找规律 a[1]=1; ...
scnublxx
2024年8月22日 18:19
不连续1的子串 题解:
P1726
回复 0
|
赞 7
|
浏览 1.1k
无脑回溯+剪枝 #include<iostream> using namespace std; int sum=0; void backtrack(int t,int len,string str) { if(str.length()==len) { sum++; return; } for(int i = 0; i <= 1; i++) { int l = str.length()-1; if(...
takanasi
2024年5月29日 18:55
不连续1的子串 题解:
P1726
回复 0
|
赞 2
|
浏览 1.7k
#include <iostream> #include <cstdio> using namespace std; const int N = 2e5 + 100; int dp[N][2]; int n; int main(){ cin >> n; dp[1][0] = 1; dp[1][1] = 1; for(int i = 2; i <= n; i ++){ dp[i][1] += dp[i - 1][0]; dp[i][0] += dp[i - 1][1] + dp[i -...
陈银波
2024年3月3日 23:48
不连续1的子串 题解:
P1726
回复 0
|
赞 15
|
浏览 1.6k
动态规划解法 dp0 的第 i 个元素表示第 i 个元素为 0 时可能数(前 i+1 个字符满足条件) dp1 的第 i 个元素表示第 i 个元素为 1 时可能数(前 i+1 个字符满足条件) #include<bits/stdc++.h> using namespace std; int compute(int n) { if (n == 0 && n == 1) { return 0; } int res = 0; vector<int> dp0(n);...
lenny
2023年7月27日 20:27
不连续1的子串 题解:(找规律)
P1726
回复 0
|
赞 17
|
浏览 1.9k
本题与厦门大学机试题01字符串类似,也是考察到找数学规律 根据题意推理: 当n=1时 组合为0 1 共计2种 当n=2时 组合为00 10 01 共计3种 当n=3时 组合为000 100 010 001 101 共计5种 综上可以考虑此为斐波那契数列。 1 1 2 3 5 8 …… 简单验证如下: 当输入n=1 输出2 数列第3项 当输入n=2 输出3 数列第4项 当输入n=3 输出5 数列第5项 因此只需要构造出斐波那契数列,输出第n+2项目的结果即可 #include <b...
1
2
题目
不连续1的子串
题解数量
13
发布题解
在线答疑
热门题解
1
不连续1的子串 题解:(找规律)
2
不连续1的子串 题解:
3
不连续1的子串 题解:
4
不连续1的子串 题解:c++,是N阶楼梯上楼,不能连续上1层问题的变形
5
不连续1的子串 题解:找规律+动规模版
6
规律题(手动推完前四个就找到规律了
7
不连续1的子串 题解:
8
这题应该是动归啊 附带一个镜像题
9
不连续1的子串 题解:
10
不连续1的子串 题解:纯递归