Educational Codeforces Round 125 (Rated for Div. 2)E.Star MST

Posted Lnn.

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 125 (Rated for Div. 2)E.Star MST相关的知识,希望对你有一定的参考价值。

前言:歪比巴卜


题目传送门


  题目类型:dp、MST、完全图
  解析: 1.定义dp[i][j]为i个点连接点1,最大边权<=j的方案数
  2.原理:uv相连,边权Wuv >= max( Wu1 , Wv1 ) , 所以当前与1边权最大的点有清晰的计数方法
  3.以小状态更新大状态:dp[i][j]更新dp[i+z][j+1],具体的,新增z个(与点1边权)为j+1的点,每个点连接(与1边权)<=j的点,贡献(k-j)^(z* i);z个点互连贡献(k-j) ^(z*(z-1)/2);再乘上n-i-1个点中选z个的方案数字。
  4.新增的点数z可以为0:相当于前缀和,把<=j的方案全拿过来

  code:

#include <bits\\stdc++.h>
#define Lnnnb return 0;
#define ll long long
#define endl '\\n'
#define mem(a) memset(a,0,sizeof(a))
#define maxn 303
#define mod 998244353

using namespace std;
void eninit();
ll n,maxx,dp[maxn][maxn],c[maxn][maxn],qpow[maxn][101010];

void finit()
    for(ll i = 1 ; i <= 251 ; ++i)
        qpow[i][0] = 1;
        for(ll j = 1 ; j <= 99999 ; ++j)
            qpow[i][j] = qpow[i][j-1] * i%mod;
        
    
    c[0][0] = 1;
    for(ll i = 1 ; i <= 251 ; ++i)
        c[i][0] = 1;
        for(ll j = 1 ; j <= i ; ++j)
            c[i][j] = (c[i-1][j] + c[i-1][j-1])%mod;
        
    


void scan()
    cin >> n >> maxx ;


void solve()
    dp[0][0] = 1;
    for(ll i = 0 ; i <= n-1 ; ++i)
        for(ll j = 0 ; j <= maxx-1 ; ++j)
            for(ll z = 0 ; z <= n-1-i ; ++z)
                ll pw = z*(z-1)/2 + z*i;
                dp[i+z][j+1] += (dp[i][j] * c[n-i-1][z]%mod * qpow[ maxx-j ][ pw ]%mod ) ;
                dp[i+z][j+1] %= mod;
            
        
    
    cout << dp[n-1][maxx] << endl ;


int main()
    ios::sync_with_stdio(false);
    ///cin.tie(0);cout.tie(0);
    finit();
    ll t = 1;
    ///cin >> t ;
    while(t--)
        scan();
        solve();
        eninit();
    
    Lnnnb


void eninit()



以上是关于Educational Codeforces Round 125 (Rated for Div. 2)E.Star MST的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27