# Codeforces 1097G

CF1097G

### 题意

$n \leq 10^5 k \leq 200$

### 题解

$$x^k=\sum_{i=0}^k \binom{x}{i}S(k,i)i!$$

$$x^k=\sum_{i=0}^k \frac{x!}{(x-i)!}S(k,i)$$

### 代码

#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define p 1000000007
#define rt register int
#define ll long long
using namespace std;
ll x=0;char zf=1;char ch=getchar();
while(ch!='-'&&!isdigit(ch))ch=getchar();
if(ch=='-')zf=-1,ch=getchar();
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();return x*zf;
}
void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);}
void writeln(const ll y){write(y);putchar('\n');}
int k,m,n,x,y,z,cnt;
vector<int>e[100010];
int S[205][205],f[100100][205],mi[100010],sz[100010],ans[100010];
void dfs(int x,int pre){
f[x][0]=sz[x]=1;
for(auto v:e[x])if(v!=pre){
dfs(v,x);
for(rt i=min(sz[v]-1,k-1);i>=0;i--){
int val=f[v][i];
if(!i)val=1ll*val*(1-mi[sz[v]])%p;
(ans[i+1]+=1ll*val*(1-mi[n-sz[v]])%p)%=p;
(f[v][i+1]+=val)%=p;
}
for(rt i=min(sz[x]-1,k);i>=0;i--)
for(rt j=1;j<=sz[v]&&i+j<=k;j++){
const int val=1ll*f[x][i]*f[v][j]%p;
if(i)(ans[i+j]+=val)%=p;
(f[x][i+j]+=val)%=p;
}
sz[x]+=sz[v];
}
}
#define inv2 500000004
int main(){
S[0][0]=1;
for(rt i=1;i<=k;i++)
for(rt j=1;j<=i;j++)S[i][j]=(S[i-1][j-1]+1ll*S[i-1][j]*j%p)%p;
for(rt i=1;i<n;i++){
e[x].push_back(y);
e[y].push_back(x);
}
mi[0]=1;
for(rt i=1;i<=n;i++)mi[i]=1ll*mi[i-1]*inv2%p;
dfs(1,0);
int ret=0,jc=1;
for(rt i=0;i<=k;i++)(ret+=1ll*S[k][i]*jc%p*ans[i]%p)%=p,jc=1ll*jc*(i+1)%p;
for(rt i=1;i<=n;i++)ret=2ll*ret%p;
cout<<(ret+p)%p;
return 0;
}

posted @ 2019-01-09 17:52  Kananix  阅读(366)  评论(1编辑  收藏  举报