文章

10

粉丝

0

获赞

12

访问

1.0k

头像
不连续1的子串 题解:纯递归
P1726 中山大学机试题
发布于2026年2月23日 14:57
阅读数 20

#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++;

        return;

    }

 

    if (str[n - 1] == '0')

    {

        str[n] = '0';

        f(n + 1);

        str[n] = '1';

        f(n + 1);

    }

    else

    {

        str[n] = '0';

        f(n + 1);

    }

}

 

int main()

{

    cin >> N;

    f(1);

    cout << counts << endl;

    return 0;

}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发