結果

問題 No.196 典型DP (1)
ユーザー 🐬hec🐬hec
提出日時 2015-07-30 17:07:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,656 bytes
コンパイル時間 1,232 ms
コンパイル使用メモリ 147,428 KB
実行使用メモリ 66,596 KB
最終ジャッジ日時 2023-09-24 22:16:37
合計ジャッジ時間 3,446 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 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,376 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,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,508 KB
testcase_13 AC 3 ms
4,888 KB
testcase_14 AC 3 ms
5,240 KB
testcase_15 AC 6 ms
9,848 KB
testcase_16 AC 9 ms
16,172 KB
testcase_17 AC 13 ms
22,156 KB
testcase_18 AC 17 ms
28,524 KB
testcase_19 AC 19 ms
30,556 KB
testcase_20 AC 23 ms
35,156 KB
testcase_21 AC 23 ms
35,300 KB
testcase_22 AC 23 ms
35,388 KB
testcase_23 AC 34 ms
48,612 KB
testcase_24 AC 30 ms
43,604 KB
testcase_25 AC 30 ms
43,056 KB
testcase_26 AC 45 ms
66,496 KB
testcase_27 AC 45 ms
66,492 KB
testcase_28 AC 45 ms
66,532 KB
testcase_29 AC 44 ms
66,596 KB
testcase_30 AC 45 ms
66,500 KB
testcase_31 AC 28 ms
34,872 KB
testcase_32 AC 27 ms
35,036 KB
testcase_33 AC 27 ms
34,868 KB
testcase_34 AC 28 ms
34,984 KB
testcase_35 AC 27 ms
34,868 KB
testcase_36 AC 27 ms
34,924 KB
testcase_37 AC 23 ms
35,044 KB
testcase_38 AC 27 ms
34,936 KB
testcase_39 AC 26 ms
34,952 KB
testcase_40 AC 27 ms
34,896 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const ll mod= 1000000007;
const int nmax=2010;

vi graph[nmax];
int num[nmax];
ll dp[nmax][nmax];


void dfs(int v,int p){
	for(auto &v2:graph[v]) if(v2!=p) dfs(v2,v);
	rep(i,nmax) dp[v][i]=0;
	dp[v][0]=1LL,num[v]=0;
	for(auto &v2:graph[v])if(v2!=p) {
		ll dp2[nmax];
		rep(i,nmax) dp2[i]=0;
		rep(i,num[v]+1)rep(j,num[v2]+1)
			dp2[i+j]=(dp2[i+j]+dp[v][i]*dp[v2][j])%mod;
		rep(i,nmax) dp[v][i]=dp2[i];
		num[v]+=num[v2];
	}
	num[v]++,dp[v][num[v]]=1;
	return;
}


int main(void){
	int N,K;
	cin >> N >> K;
	rep(i,N-1){
		int a,b;
		cin >> a >> b;
		graph[a].pb(b);
		graph[b].pb(a);
	}
	dfs(0,-1);
	cout << dp[0][K] << endl;
	return 0;
}
0