結果

問題 No.196 典型DP (1)
ユーザー chocopuuchocopuu
提出日時 2019-05-06 20:46:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,000 bytes
コンパイル時間 1,695 ms
コンパイル使用メモリ 169,564 KB
実行使用メモリ 69,872 KB
最終ジャッジ日時 2023-09-10 19:00:55
合計ジャッジ時間 7,997 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,768 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,452 KB
testcase_13 AC 3 ms
4,728 KB
testcase_14 AC 3 ms
5,104 KB
testcase_15 AC 6 ms
9,240 KB
testcase_16 AC 9 ms
15,200 KB
testcase_17 AC 18 ms
21,484 KB
testcase_18 AC 45 ms
27,852 KB
testcase_19 AC 47 ms
29,916 KB
testcase_20 AC 43 ms
34,380 KB
testcase_21 AC 58 ms
34,648 KB
testcase_22 AC 66 ms
33,992 KB
testcase_23 AC 766 ms
48,292 KB
testcase_24 AC 480 ms
43,188 KB
testcase_25 AC 461 ms
42,684 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>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
string get_str(string s) {
	s+=',';
	string ret="";
	for(int i=0; i<s.size(); i++) {
		if(s[i]==',') ret+="=%ld, ";
		else ret+=s[i];
	}
	return ret;
}
#define dump(...) printf(get_str(#__VA_ARGS__).c_str(),__VA_ARGS__);cout<<endl
 
#define endl '\n'
#define IOS()                     \
	ios_base::sync_with_stdio(0); \
	cin.tie(0)
 
//******************************************************************************
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

int N,K;
vint g[2020];
int dp[2020][2020];
int sz[2020];

void dfs(int now,int par){
	int num = 1;
	dp[now][0]=1;
	for(auto e:g[now]){
		if(e==par)continue;
		dfs(e,now);
		num+=sz[e];
		int new_dp[2020]={};
		for(int i = 0;i < num+1;i++){
			for(int j = 0;j < sz[e]+1;j++){
				if(i+j>num)continue;
				(new_dp[i+j]+=dp[now][i]*dp[e][j])%=MOD;
			}
		}
		swap(dp[now],new_dp);
	}
	dp[now][num]=1;
	sz[now]=num;
}

signed main()
{
	//IOS();
	cin>>N>>K;
	rep(i,0,N-1){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0,-1);
	cout<<dp[0][K]<<endl;
}
0