zoukankan      html  css  js  c++  java
  • ZJU-ICPC Summer 2020 Contest 9 F-FFT

    引用博客:
    带边数的无向连通图计数

    Pretty is a smart girl who loves math very much.

    She has already learned FFT algorithm.

    She loves traveling and she is looking forward to visiting more cities.

    A country is defined as Pretty Country if and only if every two cities in the country have a path.

    Notice the road is biconditional.

    Given the number of roads m and the number of cities (n), Pretty wants to know the number of Pretty Country.

    Since the number may be very big, please mod (998244353).

    Here mod means modulo operation.

    Input
    One line containing an integer (n). ((1 leq n leq 100))
    (m) is (0,1,2,3,dots, frac{n(n-1)}{2}).

    Output
    (frac{n(n-1)}{2}) lines.

    The number means the answer.

    Examples
    inputCopy
    2
    outputCopy
    0
    1
    inputCopy
    5
    outputCopy
    0
    0
    0
    0
    125
    222
    205
    120
    45
    10
    1

    
    #include<bits/stdc++.h>
    using namespace std;
    
    #define d(x) ( x * (x - 1) / 2)
    
    const int mod = 998244353;
    
    int n;
    long long H[105][5000],F[5000];
    long long fac[5005],inv[5005];
    
    long long ksm(long long x,long long y){
        long long z = 1; 
        while(y){
            if(y & 1) z = z * x % mod;
            y >>= 1;
            x = x * x % mod;
        }
        return z;
    }
    long long C(int n,int m){
        if(n < m || m < 0) return 0;
        if(n == m || m == 0) return 1;
        return fac[n] * inv[m] % mod * inv[n - m] % mod;
    }
    
    int main(){
        fac[0] = 1; for(int i = 1; i <= 5000; ++ i) fac[i] = fac[i - 1] * i % mod;
        inv[5000] = ksm(fac[5000],mod - 2); for(int i = 4999; i >= 0; -- i) inv[i] = inv[i + 1] * (i + 1) % mod;
         
        scanf("%d",&n);
        for(int i = 1; i <= n; ++ i) H[i][d(i)] = 1;
        for(int i = 1; i <= n; ++ i)
        for(int j = d(i); j >= 0; -- j){
            if(H[i][j]){
                for(int k = 1; i + k <= n; ++ k){
                    H[i + k][j + d(k)] += mod - H[i][j] * C(i + k - 1, k) % mod; H[i + k][j + d(k)] %= mod;
                }
            }
        }
        for(int j = 0; j <= d(n); ++ j){
            for(int k = j; k <= d(n); ++ k)
            F[j] += H[n][k] * C(k,j) % mod , F[j] %= mod;
            
            F[j] = (F[j] % mod + mod) % mod;
            printf("%lld
    ",F[j]);
        }
        
        return 0;
    }
    
    
  • 相关阅读:
    FFMPEG 中dts和pts区别
    time_base
    [总结]FFMPEG视音频编解码零基础学习方法
    autolayout收集,适配,自动布局 状态栏 applicationFrame
    滑出式导航面板
    WPF与WCF c#
    App Icons on iPad and iPhone UI 尺寸
    mac iPhone管理工具
    scrollview背景
    网络编程链接
  • 原文地址:https://www.cnblogs.com/zzhzzh123/p/13386139.html
Copyright © 2011-2022 走看看