結果

問題 No.196 典型DP (1)
ユーザー takayuta1999takayuta1999
提出日時 2015-04-26 22:09:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 903 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 49,008 KB
実行使用メモリ 16,884 KB
最終ジャッジ日時 2023-09-18 11:51:51
合計ジャッジ時間 2,245 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 2005
#define MOD 1000000007

using namespace std;
typedef long long int ll;

vector <int> vec[SIZE];
vector <int> dp[SIZE];
int nd[SIZE];

void dfs(int v=0,int p=-1)
{
	nd[v]=1;
	dp[v].push_back(1);
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		if(to!=p)
		{
			dfs(to,v);
			nd[v]+=nd[to];
			vector <int> nd;
			nd.resize(dp[v].size()+dp[to].size()-1,0);
			for(int j=0;j<dp[v].size();j++)
			{
				for(int k=0;k<dp[to].size();k++)
				{
					nd[j+k]+=(ll) dp[v][j]*(ll) dp[to][k]%MOD;
					if(nd[j+k]>=MOD) nd[j+k]-=MOD;
				}
			}
			dp[v]=nd;
		}
	}
	dp[v].push_back(1);
}
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	dfs();
	printf("%d\n",dp[0][k]);
	return 0;
}
0