結果

問題 No.196 典型DP (1)
ユーザー autumn-eelautumn-eel
提出日時 2018-01-01 20:49:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 795 bytes
コンパイル時間 1,810 ms
コンパイル使用メモリ 167,532 KB
実行使用メモリ 31,780 KB
最終ジャッジ日時 2023-08-24 15:49:05
合計ジャッジ時間 9,026 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 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 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 6 ms
8,300 KB
testcase_16 AC 8 ms
12,376 KB
testcase_17 AC 21 ms
16,520 KB
testcase_18 AC 64 ms
20,848 KB
testcase_19 AC 69 ms
22,664 KB
testcase_20 AC 63 ms
27,024 KB
testcase_21 AC 88 ms
26,928 KB
testcase_22 AC 98 ms
26,900 KB
testcase_23 AC 1,190 ms
27,072 KB
testcase_24 AC 740 ms
27,020 KB
testcase_25 AC 713 ms
26,944 KB
testcase_26 TLE -
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>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

int dp[3000][3000];//頂点iの個をj個塗る通り数
vector<int>E[3000];
int siz[3000];//頂点iを根とする部分木のサイズ

void rec(int v,int p){
	dp[v][0]=1;
	dp[v][siz[v]]=1;
	for(auto u:E[v]){
		if(u==p)continue;
		rec(u,v);
		for(int i=siz[v]-1;i>0;i--){
			for(int j=1;j<=siz[u]&&j<=i;j++){
				(dp[v][i]+=(dp[u][j]*(ll)dp[v][i-j])%MOD)%=MOD;
			}
		}
	}
}
void dfs(int v,int p){
	siz[v]=1;	
	for(int u:E[v]){
		if(u==p)continue;
		dfs(u,v);
		siz[v]+=siz[u];
	}
}
int main(){
	int n,k;scanf("%d%d",&n,&k);
	rep(i,n-1){
		int a,b;scanf("%d%d",&a,&b);
		E[a].push_back(b);
		E[b].push_back(a);
	}
	dfs(0,-1);
	rec(0,-1);
	cout<<dp[0][k]<<endl;
}
0