結果

問題 No.196 典型DP (1)
ユーザー Kmcode1Kmcode1
提出日時 2015-04-26 23:03:15
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,609 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 99,640 KB
実行使用メモリ 38,456 KB
最終ジャッジ日時 2023-09-18 09:03:28
合計ジャッジ時間 6,485 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,764 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 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 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 9 ms
33,672 KB
testcase_27 AC 248 ms
34,240 KB
testcase_28 TLE -
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 = jj; j >= 0; j--){
			//choose from g[b][i]
			for (int kk = 1; kk <= 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