文章

101

粉丝

1

获赞

687

访问

20.5k

头像
不连续1的子串 题解:c++,是N阶楼梯上楼,不能连续上1层问题的变形
P1726 中山大学机试题
发布于2026年3月5日 16:53
阅读数 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){
        cout << step(n,0) + step(n,1)<< endl;
    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发