zoukankan      html  css  js  c++  java
  • [Lydsy2017省队十连测]最长路径

    SOL:

     同JZOJ5061

    #include<bits/stdc++.h>
    #define LL long long
    #define N 3007
    using namespace std;
    LL n,mo,c[N][N],f[N],g[N],anw[N];
    inline LL qsm(LL x,LL y) {
        static LL anw;
        for (anw=1;y;y=y>>1,x=x*x%mo) if (y&1) anw=anw*x%mo;
        return anw;
    }
    signed main () {
        scanf("%lld%lld",&n,&mo);
        c[0][0]=1;
        for (int i=1;i<=n;i++) {
            c[i][0]=c[i][i]=1;
            for (int j=1;j<i;j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mo;
        }
    //   for (int i=1;i<=n;i++) {
    //      for (int j=0;j<=i;j++) cerr<<c[i][j]<<" ";
    //      puts("");
    //  }
        for (int i=0;i<=n;i++) f[i]=qsm(2,i*(i-1)/2);
    //  for (int i=0;i<=n;i++) cerr<<f[i]<<' '; puts("");
        g[1]=1;
        for (int i=2;i<=n;i++) {
            g[i]=f[i];
            for (int j=1;j<i;j++) g[i]-=c[i][j]*g[j]%mo*f[i-j]%mo,g[i]=(g[i]%mo+mo)%mo;
        }
    //  for (int i=0;i<=n;i++) cerr<<g[i]<<' ';
        for (int i=1;i<=n;i++)
         for (int j=0;i+j<=n;j++)
          anw[i+j]+=f[n-i-j]*f[j]%mo*c[n-1][i-1]%mo*c[n-i][j]%mo*g[i]%mo
          ,anw[i+j]%=mo;
        for (int i=1;i<=n;i++) printf("%lld
    ",anw[i]);
    }
  • 相关阅读:
    寄存器基础知识
    基础知识
    架构
    Mac下Apache服务器的初步搭建
    ios字体简单设定
    xcode中自定义log打印
    jQuery打印插件
    ionic3生命周期钩子
    ES5 数组方法map
    $compile的妙用
  • 原文地址:https://www.cnblogs.com/rrsb/p/9126910.html
Copyright © 2011-2022 走看看