当前位置:网站首页>Educational Codeforces Round 116 (Rated for Div. 2) E. Arena

Educational Codeforces Round 116 (Rated for Div. 2) E. Arena

2022-07-05 05:31:00 solemntee

 Insert picture description here
d p [ i ] [ j ] [ k ] dp[i][j][k] dp[i][j][k] The maximum value is i i i The length is j j j Less than j − 1 j-1 j1 The number of is k k k individual
After considering a round, the state changes to d p [ i − ( j − 1 ) ] [ j − k ] [ . . . ] dp[i-(j-1)][j-k][...] dp[i(j1)][jk][...], Therefore, the transfer is
d p [ i ] [ j ] [ k ] = ∑ ( C j k ∗ ( j − 1 ) k ∗ d p [ i − ( j − 1 ) ] [ j − k ] [ l ] ) dp[i][j][k]=\sum(C^k_j*(j-1)^k*dp[i-(j-1)][j-k][l]) dp[i][j][k]=(Cjk(j1)kdp[i(j1)][jk][l])
Find out k k k It has nothing to do with the transfer and scrolls directly .

#include<bits/stdc++.h>
using namespace std;
int dp[505][505];
const int mod=998244353;
long long poww(long long a,long long b)
{
    
    long long t=1;
    if(b==0)return 1;
    while(b>1)
    {
    
        if(b%2==1)t=(t*a)%mod;
        a=a*a%mod;
        b/=2;
    }
    return a*t%mod;
}
long long P1[1005],P2[1005];
void init()
{
    
    P1[0]=1;
    P2[0]=1;
    for(int i=1;i<=505;i++)P1[i]=(P1[i-1]*i)%mod;
    for(int i=1;i<=505;i++)P2[i]=(P2[i-1]*poww(i,mod-2))%mod;
}
int main()
{
    
    init();
    int n,x;

    scanf("%d%d",&n,&x);
    for(int i=1;i<=x;i++)
        for(int j=1;j<=n;j++)
            for(int k=0;k<j;k++)
    {
    
        if(j==1)dp[i][j]+=1;
        else if(j==i&&k!=j-1)continue;
        else if(j>i)continue;
        else
        {
    

                dp[i][j]=(dp[i][j]+poww(j-1,k)*P1[j]%mod*P2[k]%mod*P2[j-k]%mod*dp[i-j+1][j-k])%998244353;

        }
    }
    ///
// for(int i=1;i<=x;i++)
// for(int j=1;j<=n;j++)
// for(int k=0;k<j;k++)
// {
    
// printf("%d %d %d %lld\n",i,j,k,dp[i][j][k]);
// }
    long long ans=0;
    for(int i=1;i<=x;i++)
    {
    
        ans=(ans+dp[i][n])%998244353;
    }
    printf("%lld",((poww(x,n)-ans)%mod+mod)%mod);
    return 0;
}

原网站

版权声明
本文为[solemntee]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140621453073.html