1 solutions

  • 1
    @ 2026-2-2 11:58:46
    #include<bits/stdc++.h>
    using namespace std;
    long long a[1110]={1,1,2,4,7,11};
    int main()
    {
        int n;
        while(cin>>n,n)
        {
            if(n==1) 
            {
                cout<<1<<endl;
                continue;
            }
            if(n==2)
            {
                cout<<2<<endl;
                continue;
            }
            if(n==3)
            {
                cout<<4<<endl;
                continue;
            }
            for(int i=3;i<=n;i++)
            {
                a[i]=a[i-1]+a[i-2]+a[i-3];
            }
            cout<<a[n]<<endl;
        }
        return 0;
    }
    
    • 1

    Information

    ID
    3031
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    1
    Tags
    (None)
    # Submissions
    12
    Accepted
    3
    Uploaded By