zoukankan      html  css  js  c++  java
  • 2019牛客暑期多校训练营(第五场)

    #include<bits/stdc++.h>
    
    using namespace std;
    int n;
    int main(){
        int T;
        scanf("%d",&T);
        while (T--){
            scanf("%d",&n);
            for (int i=1;i<=n;i++){
                printf("%d",n);
            }
            printf("
    ");
        }
    }

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    char s[1000100];
    ll mod;
    struct node
    {
        ll a[2][2];
    
        node operator*(const node &b) const
        {
            node res;
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    res.a[i][j] = 0;
                    for (int k = 0; k < 2; k++)
                    {
                        res.a[i][j] = (res.a[i][j] + a[i][k] * b.a[k][j]) % mod;
                    }
                }
            }
            return res;
        }
    };
    
    node pow(node b,ll c)
    {
        node res;
        res.a[0][0] = 1;
        res.a[1][0] = 0;
        res.a[0][1] = 0;
        res.a[1][1] = 1;
        while (c)
        {
            if (c & 1)
            {
                res = res * b;
            }
            c >>= 1;
            b = b * b;
        }
        return res;
    }
    
    int main()
    {
        ll a,b,x0,x1;
        scanf("%lld%lld%lld%lld",&x0,&x1,&a,&b);
        node f;
        f.a[0][0] = 0;
        f.a[1][0] = 1;
        f.a[0][1] = b;
        f.a[1][1] = a;
        node ans;
        ans.a[0][0]=1;
        ans.a[0][1]=0;
        ans.a[1][0]=0;
        ans.a[1][1]=1;
        scanf("%s",s);
        ll len=strlen(s);
        scanf("%lld",&mod);
        for (int i=0; i<len; i++)
        {
            ans=pow(ans,10)*pow(f,s[i]-'0');
        }
        printf("%lld
    ",(x0*ans.a[0][0]+x1*ans.a[1][0])%mod);
    }
    

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const ll mod=998244353;
    const int N=3050;
    ll C[N][N],n,m,dp[N],ans;
    char s[1000000],t[1000000];
    int main()
    {
        for (int i=1; i<3050; i++)
        {
            C[i][0]=C[i][i]=1;
            for (int j=1; j<i; j++)
            {
                C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
            }
        }
        int T;
        scanf("%d",&T);
        while (T--)
        {
            scanf("%lld%lld",&n,&m);
            scanf("%s",s+1);
            scanf("%s",t+1);
    
            for (int j=0; j<=m+1; j++)
            {
                dp[j]=0;
            }
            dp[1]=(s[n]>t[m]);
            for (int i=n-1; i>=1; i--)
            {
                for (int j=min(m,n-i+1); j>=1; j--)
                {
                    if (s[i]>t[m-j+1])
                    {
                        dp[j]=(dp[j]+C[n-i][j-1])%mod;
                        ////如果i位  s更大  ,可以由长度j-1任意首位递推
                    }
                    if (s[i]==t[m-j+1])
                    {
                        dp[j]=(dp[j]+dp[j-1])%mod;
                    }
                }
            }
            ans=dp[m];
            for (int i=1; i<=n; i++)
            {
                if (s[i]!='0')
                {
                    for (int j=m; j+i<=n; j++)
                    {
                        ans=(ans+C[n-i][j])%mod;
                    }
                }
            }
            printf("%lld
    ",(ans+mod)%mod);
        }
    }

  • 相关阅读:
    ....
    CodeForces 375A(同余)
    POJ 2377 Bad Cowtractors (最小生成树)
    POJ 1258 AgriNet (最小生成树)
    HDU 1016 Prime Ring Problem(全排列)
    HDU 4460 Friend Chains(bfs)
    POJ 2236 Wireless Network(并查集)
    POJ 2100 Graveyard Design(尺取)
    POJ 2110 Mountain Walking(二分/bfs)
    CodeForces 1059B Forgery(模拟)
  • 原文地址:https://www.cnblogs.com/Accpted/p/11284323.html
Copyright © 2011-2022 走看看