結果

問題 No.196 典型DP (1)
ユーザー Div9851Div9851
提出日時 2017-10-07 20:57:26
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 957 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 161,060 KB
実行使用メモリ 41,104 KB
最終ジャッジ日時 2024-04-28 12:53:25
合計ジャッジ時間 11,527 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,760 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 51 ms
7,956 KB
testcase_16 AC 401 ms
14,116 KB
testcase_17 AC 828 ms
20,144 KB
testcase_18 TLE -
testcase_19 AC 1,190 ms
28,784 KB
testcase_20 AC 25 ms
32,872 KB
testcase_21 AC 99 ms
32,864 KB
testcase_22 AC 12 ms
32,876 KB
testcase_23 AC 720 ms
33,560 KB
testcase_24 AC 52 ms
33,156 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
vector<int> G[2000];
LL dp[2000][2001];
LL tree[2000];
int N, K;
void cnt(int v, int par) {
	tree[v] = 1;
	rep(i, G[v].size()) {
		int to = G[v][i];
		if (to == par) continue;
		cnt(to, v);
		tree[v] += tree[to];
	}
}
void dfs(int v, int par) {
	dp[v][0] = 1;
	rep(i, G[v].size()) {
		int to = G[v][i];
		if (to == par) continue;
		dfs(to, v);
		for (int j = K; j >= 1; j--) {
			for (int k = 1; k <= j; k++) {
				LL t = (dp[v][j - k] * dp[to][k]) % MOD;
				(dp[v][j] += t) %= MOD;
			}
		}
	}
	(dp[v][tree[v]] += 1) %= MOD;
}
int main() {
	cin >> N >> K;
	rep(i, N - 1) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	cnt(0, -1);
	dfs(0, -1);
	cout << dp[0][K] << endl;
}
0