結果

問題 No.196 典型DP (1)
ユーザー Vi24EVi24E
提出日時 2024-02-07 01:22:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 797 bytes
コンパイル時間 4,632 ms
コンパイル使用メモリ 269,752 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-02-07 01:22:13
合計ジャッジ時間 6,520 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 AC 6 ms
6,676 KB
testcase_19 AC 7 ms
6,676 KB
testcase_20 AC 7 ms
6,676 KB
testcase_21 AC 8 ms
6,676 KB
testcase_22 AC 9 ms
6,676 KB
testcase_23 AC 13 ms
7,296 KB
testcase_24 AC 12 ms
6,676 KB
testcase_25 AC 12 ms
6,676 KB
testcase_26 AC 18 ms
12,032 KB
testcase_27 AC 20 ms
12,032 KB
testcase_28 AC 19 ms
12,032 KB
testcase_29 AC 19 ms
12,032 KB
testcase_30 AC 19 ms
12,032 KB
testcase_31 AC 14 ms
6,676 KB
testcase_32 AC 13 ms
6,676 KB
testcase_33 AC 14 ms
6,676 KB
testcase_34 AC 13 ms
6,676 KB
testcase_35 AC 14 ms
6,676 KB
testcase_36 AC 13 ms
6,676 KB
testcase_37 AC 9 ms
6,676 KB
testcase_38 AC 13 ms
6,676 KB
testcase_39 AC 13 ms
6,676 KB
testcase_40 AC 13 ms
6,676 KB
testcase_41 AC 2 ms
6,676 KB
testcase_42 AC 2 ms
6,676 KB
testcase_43 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
vector<vector<modint1000000007>> dp(3030);
vector<vector<int>> g;

void solve(int t, int p){
	if (g[t].size() == 1 && p != -1){
		dp[t] = {1, 1};
		return;
	}

	dp[t] = {1, 0};
	for (auto x : g[t]){
		if (x == p) continue;
		solve(x, t);

		vector<modint1000000007> merge(dp[t].size() + dp[x].size() - 1);
		for (int i = 0; i < (int)dp[t].size(); i++){
			for (int j = 0; j < (int)dp[x].size(); j++){
				merge[i + j] += dp[t][i] * dp[x][j];
			}
		}
		dp[t] = merge;
	}
	dp[t].back() = 1;
}

int main(){
	int n, k;
	cin >> n >> k;
	g.resize(n);
	for (int i = 0; i < n - 1; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	solve(0, -1);
	cout << dp[0][k].val() << endl;
}
0