1. 程式人生 > >[Lydsy2017省隊十連測]最長路徑

[Lydsy2017省隊十連測]最長路徑

https zoj include crazy clu tps ace return http

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\n",anw[i]); }

[Lydsy2017省隊十連測]最長路徑