## [Ccodeforces 736C] Ostap and Tree - 树形DP

f[x][0] = f[x][k+1] = 1;

#include <cstdio>
#include <algorithm>
#define ll long long
#define For(i,j,k) for(ll i=j;i<=k;i++)
using namespace std;
ll mo=1e9+7;
ll poi[10001],F[10001],nxt[10001], dep[1001],f[1001][1001],tmp[1001],ans,n,k,x,y,cnt;
bool vis[1001];
inline void add(ll x,ll y){poi[++cnt]=y;nxt[cnt]=F[x];F[x]=cnt;}
inline void dfs(ll x) {
vis[x] = 1;
f[x][0] = 1;
f[x][k+1] = 1;
for(ll i=F[x];i;i=nxt[i]) {
ll ne = poi[i];
if(vis[ne]) continue;
dep[ne] = dep[x] + 1;
dfs(ne);
For(j,0,2*k) tmp[j]=0;
For(j,0,2*k) For(t,0,2*k+1) {
if(j+t<=2*k)
tmp[min(j,t + 1)] += f[x][j] * f[ne][t], tmp[min(j,t+1)] %= mo;
else
tmp[max(j,t + 1)] += f[x][j] * f[ne][t], tmp[max(j,t+1)] %= mo;
}
For(j, 0,2*k)	f[x][j]=tmp[j];
}
}
int main() {
#ifdef orz
freopen("input", "r", stdin);
#endif
scanf("%lld %lld", &n, &k);
if(k == 0) return puts("1") & 0;
For(i,1,n-1) {
scanf("%lld %lld", &x, &y);
add(x, y);
add(y, x);
}
dfs(1);
For(i,0,k)	ans+=f[1][i],ans%=mo;
printf("%lld", ans);
}


posted on 2017-08-23 10:31  蒟蒻konjac  阅读(323)  评论(0编辑  收藏

• 随笔 - 168
• 文章 - 0
• 评论 - 33