1 solutions

  • 0
    @ 2024-12-5 18:22:03

    C++ :

    
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <set>
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define space putchar(' ')
    #define enter putchar('\n')
    typedef pair<int,int> PII;
    const int mod=1e4+7;
    const int N=2e6+10;
    const int inf=0x7f7f7f7f;
    
    
    ll gcd(ll a,ll b)
    {
        return b==0?a:gcd(b,a%b);
    }
    
    ll lcm(ll a,ll b)
    {
        return a*(b/gcd(a,b));
    }
    
    template <class T>
    void read(T &x)
    {
        char c;
        bool op = 0;
        while(c = getchar(), c < '0' || c > '9')
            if(c == '-')
                op = 1;
        x = c - '0';
        while(c = getchar(), c >= '0' && c <= '9')
            x = x * 10 + c - '0';
        if(op)
            x = -x;
    }
    template <class T>
    void write(T x)
    {
        if(x < 0)
            x = -x, putchar('-');
        if(x >= 10)
            write(x / 10);
        putchar('0' + x % 10);
    }
    
    int fa[N];
    int n,k;
    PII a[N],sum[N];
    int dp[50][50];
    int main()
    {
       read(n),read(k);
       dp[0][1]=1;
       for(int i=1;i<=k;i++)
       {
           for(int j=1;j<=n;j++)
           {
               if(j==1)
                dp[i][j]=dp[i-1][n]+dp[i-1][j+1];
               else if(j==n)
                dp[i][j]=dp[i-1][n-1]+dp[i-1][1];
               else
               dp[i][j]=dp[i-1][j-1]+dp[i-1][j+1];
           }
       }
       write(dp[k][1]);
    
    
    
    
    
    
        return 0;
    }
    
    
    
    • 1

    Information

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