/* -*- coding: utf-8 -*- * * 196.cc: No.196 典型DP (1) - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 2000; typedef long long ll; const ll MOD = 1000000007; /* typedef */ typedef vector vi; /* global variables */ int n, k; int prts[MAX_N], ncs[MAX_N]; vi nbrs[MAX_N], clds[MAX_N]; ll dp[MAX_N][MAX_N + 1], udp[2][MAX_N + 1]; /* subroutines */ void make_tree(int u, int pu = -1) { prts[u] = pu; ncs[u] = 1; vi &nbru = nbrs[u]; for (vi::iterator vit = nbru.begin(); vit != nbru.end(); vit++) { int &v = *vit; if (v != pu) { clds[u].push_back(v); make_tree(v, u); ncs[u] += ncs[v]; } } } void rec(int u) { int usize = sizeof(ll) * (ncs[u] + 1); memset(udp[0], 0, usize); udp[0][0] = 1; int cur = 0, nxt = 1; int sumnc = 0; vi &cldu = clds[u]; for (vi::iterator vit = cldu.begin(); vit != cldu.end(); vit++) rec(*vit); for (vi::iterator vit = cldu.begin(); vit != cldu.end(); vit++) { int &v = *vit; //printf("u=%d: sumnc=%d, ncs[%d]=%d\n", u, sumnc, v, ncs[v]); //for (int j = 0; j <= sumnc; j++) printf(" %lld", udp[cur][j]); //putchar('\n'); //for (int j = 0; j <= ncs[v]; j++) printf(" %lld", dp[v][j]); //putchar('\n'); memset(udp[nxt], 0, usize); for (int i = sumnc; i >= 0; i--) for (int j = ncs[v]; j >= 0; j--) udp[nxt][i + j] = (udp[nxt][i + j] + udp[cur][i] * dp[v][j] % MOD) % MOD; sumnc += ncs[v]; cur ^= 1, nxt ^= 1; } udp[cur][ncs[u]] = 1; memcpy(dp[u], udp[cur], usize); } /* main */ int main() { cin >> n >> k; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; nbrs[a].push_back(b); nbrs[b].push_back(a); } make_tree(0); //for (int i = 0; i < n; i++) printf("%d ", ncs[i]); putchar('\n'); rec(0); printf("%lld\n", dp[0][k]); for (int i = 0; false && i < n; i++) { printf("%d:", i); for (int j = 0; j <= n; j++) printf(" %lld", dp[i][j]); putchar('\n'); } return 0; }