結果

問題 No.196 典型DP (1)
ユーザー Kmcode1Kmcode1
提出日時 2015-04-26 23:06:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,621 bytes
コンパイル時間 2,146 ms
コンパイル使用メモリ 98,952 KB
実行使用メモリ 31,260 KB
最終ジャッジ日時 2023-09-18 09:23:12
合計ジャッジ時間 7,346 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,764 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 RE -
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
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<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<valarray>
//#include<bits/stdc++.h>
//using namespace std;
using namespace std;
#define MOD 1000000007

int n;
int k;
#define MAX 2001
vector<int> g[MAX];
bool use[MAX];
vector<int> v[MAX];
int countt[MAX];
inline void dfs(int b){
	use[b] = true;
	for (int i = 0; i < v[b].size(); i++){
		if (use[v[b][i]] == false){
			dfs(v[b][i]);
			g[b].push_back(v[b][i]);
		}
	}
}
inline void dfs2(int b){
	countt[b] = 1;
	for (int i = 0; i < g[b].size(); i++){
		dfs2(g[b][i]);
		countt[b] += countt[g[b][i]];
	}
}
long long int dp[MAX][MAX];
inline void dfs3(int b){
	for (int i = 0; i < g[b].size(); i++){
		dfs3(g[b][i]);
	}
	dp[b][0] = 1;
	dp[b][countt[b]] = 1;
	for (int i = 0; i < g[b].size(); i++){
		int jyo = min(k, countt[g[b][i]]);
		int jj = min(jyo + 1, k);
		for (int j = k/*jj*/; j >= 0; j--){
			//choose from g[b][i]
			for (int kk = 1; kk <=k/*<= jyo&&kk <= j*/; kk++){
				dp[b][j] += dp[g[b][i]][kk] * dp[b][j - kk];
				dp[b][j] %= MOD;
			}
		}
	}
}
int main(){
	scanf("%d%d", &n, &k);
	for (int i = 1; i < n; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs(0);
	dfs2(0);
	dfs3(0);
	printf("%lld\n", dp[0][k]);
	return 0;
}
0