結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 1 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,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 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,280 KB
testcase_16 AC 8 ms
12,464 KB
testcase_17 AC 18 ms
16,608 KB
testcase_18 AC 59 ms
20,660 KB
testcase_19 AC 63 ms
22,652 KB
testcase_20 AC 54 ms
26,780 KB
testcase_21 AC 79 ms
26,972 KB
testcase_22 AC 89 ms
26,812 KB
testcase_23 AC 1,181 ms
27,088 KB
testcase_24 AC 730 ms
26,928 KB
testcase_25 AC 701 ms
26,908 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;
	siz[v]=1;
	for(auto u:E[v]){
		if(u==p)continue;
		rec(u,v);
		siz[v]+=siz[u];
		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;
			}
		}
	}
	dp[v][siz[v]]=1;
}
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);
	}
	rec(0,-1);
	cout<<dp[0][k]<<endl;
}
0