1 solutions

  • 0
    @ 2025-3-3 16:28:35

    C++ :

    #include <iostream>
    #include <string.h>
    using namespace std;
    int total = 0;
    void fun(int n, char* str)
    {
        if(n==0)
        {
            char* p1 = strstr(str,"111");
            //char* p2 = strstr(str,"000");
            if(p1 == NULL)
            {
                total++;
            }
        }
        else{
            str[n-1]='1';
            fun(n-1,str);
            str[n-1]='0';
            fun(n-1,str);
            }
    }
    
    int main()
        {
            char str[41]={0};
            int n;
            scanf("%d",&n);
            fun(n,str);
            cout<<total<<endl;
            return 0;
        }
    
    • 1

    Information

    ID
    10220
    Time
    1000ms
    Memory
    16MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By