結果

問題 No.196 典型DP (1)
ユーザー Lepton_sLepton_s
提出日時 2015-04-26 22:34:12
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,071 bytes
コンパイル時間 573 ms
コンパイル使用メモリ 79,256 KB
実行使用メモリ 33,056 KB
最終ジャッジ日時 2023-09-18 12:05:11
合計ジャッジ時間 2,407 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 4 ms
7,624 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 31 ms
32,800 KB
testcase_32 AC 31 ms
32,752 KB
testcase_33 AC 31 ms
32,860 KB
testcase_34 AC 31 ms
32,864 KB
testcase_35 AC 31 ms
32,864 KB
testcase_36 AC 29 ms
32,704 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 30 ms
32,884 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<25;
typedef pair<int,int> P;
typedef long long ll;
typedef unsigned long long ull;
#define MAX_N 2000
int N, K;
vector<int> g[MAX_N];
ll dp[MAX_N][MAX_N];
ll mod = 1000000007;

ll dfs(int u){
	dp[u][0] = 1;
	ll sz = 1;
	for(int i = 0; i < g[u].size(); i++){
		int v = g[u][i];
		ll t = dfs(v);
		sz += t;
		for(int j = sz-1; j >= 0; j--){
			for(int k = 1; k <= (min<int>(t, j)); k++){
				(dp[u][j]+=dp[u][j-k]*dp[v][k])%=mod;
			}
		}
	}
	dp[u][sz] = 1;
	return sz;
}

int main(){
	cin>>N>>K;
	for(int i = 0; i < N-1; i++){
		int a, b;
		cin>>a>>b;
		g[a].push_back(b);
	}
	dfs(0);
	cout<<dp[0][K]<<endl;
	return 0;
}
0