結果

問題 No.196 典型DP (1)
ユーザー pekempeypekempey
提出日時 2016-02-20 13:17:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,247 bytes
コンパイル時間 1,501 ms
コンパイル使用メモリ 162,772 KB
実行使用メモリ 35,372 KB
最終ジャッジ日時 2023-10-23 18:40:17
合計ジャッジ時間 4,085 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
5,932 KB
testcase_13 AC 2 ms
5,932 KB
testcase_14 AC 2 ms
5,936 KB
testcase_15 AC 4 ms
10,040 KB
testcase_16 AC 5 ms
16,200 KB
testcase_17 AC 7 ms
20,312 KB
testcase_18 AC 10 ms
26,468 KB
testcase_19 AC 11 ms
30,572 KB
testcase_20 AC 14 ms
34,728 KB
testcase_21 AC 13 ms
34,728 KB
testcase_22 AC 13 ms
34,736 KB
testcase_23 AC 15 ms
34,932 KB
testcase_24 AC 14 ms
34,872 KB
testcase_25 AC 14 ms
34,880 KB
testcase_26 AC 16 ms
35,336 KB
testcase_27 AC 17 ms
35,336 KB
testcase_28 AC 17 ms
35,372 KB
testcase_29 AC 17 ms
35,328 KB
testcase_30 AC 17 ms
35,344 KB
testcase_31 AC 19 ms
34,736 KB
testcase_32 AC 19 ms
34,736 KB
testcase_33 AC 19 ms
34,736 KB
testcase_34 AC 20 ms
34,736 KB
testcase_35 AC 19 ms
34,736 KB
testcase_36 AC 18 ms
34,736 KB
testcase_37 AC 14 ms
34,728 KB
testcase_38 AC 18 ms
34,736 KB
testcase_39 AC 17 ms
34,736 KB
testcase_40 AC 19 ms
34,736 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 1 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
using namespace std;
typedef long long ll;

vector<int> G[2020];
ll dp[2020][2020];
int size[2020];
const ll mod = 1e9 + 7;

int dfs2(int curr, int prev) {
	size[curr] = 1;
	for (int next : G[curr]) if (next != prev) {
		size[curr] += dfs2(next, curr);
	}
	return size[curr];
}

void dfs(int curr, int prev) {
	dp[curr][0] = 1;
	dp[curr][size[curr]] = 1;
	for (int next : G[curr]) if (next != prev) {
		dfs(next, curr);
		repr (i, size[curr]) if (dp[curr][i] > 0) rep (j, 1, size[next] + 1) {
			
				(dp[curr][i + j] += dp[curr][i] * dp[next][j]) %= mod;
		}
	}
}

int main() {
	int N, K;
	cin >> N >> K;
	rep (i, N - 1) {
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs2(0, -1);
	dfs(0, -1);
	cout << dp[0][K] << endl;
	return 0;
}
0