# description

$s_u=\sum_{v=1}^n dis(u,v)^k$

$n\le30000,k<=150$

# sol

$m^n=\sum_{i=0}^m S(n,i)\binom mi i!$

$s_u=\sum_{v=1}^n\sum_{i=0}^k S(k,i)\binom{dis(u,v)}{i}i!=\sum_{i=0}^k S(k,i)i!\sum_{v=1}^n\binom{dis(u,v)}{i}$

# code

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int gi(){
int x=0,w=1;char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if (ch=='-') w=0,ch=getchar();
while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return w?x:-x;
}
const int N = 50005;
const int K = 155;
const int mod = 10007;
}
void Input_a(){
n=gi();k=gi();
}
void Input_b(){
n=gi();k=gi();int L=gi(),now=gi(),A=gi(),B=gi(),Q=gi(),tmp;
}
inline void mns(int &x,int y){(x+=mod-y)%=mod;}
void trans(int u,int v){
}
void retrans(int u,int v){
mns(f[u][0],f[v][0]);
for (int i=1;i<=k;++i) mns(f[u][i],(f[v][i]+f[v][i-1])%mod);
}
void dfs1(int u,int ff){
f[u][0]=1;
if (to[e]!=ff) dfs1(to[e],u),trans(u,to[e]);
}
void dfs2(int u,int ff){
if (to[e]!=ff){
retrans(u,to[e]),trans(to[e],u);
dfs2(to[e],u);
retrans(to[e],u),trans(u,to[e]);
}
}
int main(){
//	Input_a();
Input_b();
jc[0]=S[0][0]=1;
for (int i=1;i<=k;++i) jc[i]=1ll*jc[i-1]*i%mod;
for (int i=1;i<=k;++i)
for (int j=1;j<=i;++j)
S[i][j]=(S[i-1][j]*j+S[i-1][j-1])%mod;
dfs1(1,0);dfs2(1,0);
for (int i=1;i<=n;++i) printf("%d\n",ans[i]);
return 0;
}

posted @ 2018-08-15 21:47  租酥雨  阅读(172)  评论(0编辑  收藏  举报