結果

問題 No.196 典型DP (1)
ユーザー 古寺いろは
提出日時 2015-04-26 22:50:48
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 640 bytes
コンパイル時間 1,481 ms
コンパイル使用メモリ 161,428 KB
実行使用メモリ 50,888 KB
最終ジャッジ日時 2024-07-05 03:13:57
合計ジャッジ時間 2,779 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

vector<int> es[3000];
long long dp[3000][3000];
int child[3000];

long long mod = 1000000007;

int main() {
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N - 1; i++)
	{
		int a, b;
		cin >> a >> b;
		es[a].push_back(b);
	}
	for (int i = N - 1; i >= 0; i--)
	{
		child[i] = 1;
		dp[i][0] = 1;
		for (auto j : es[i]){
			for (int k = child[i] - 1; k >= 0; k--)
			{
				for (int l = child[j]; l >= 1; l--)
				{
					dp[i][k + l] += dp[i][k] * dp[j][l];
					dp[i][k + l] %= mod;
				}
			}
			child[i] += child[j];
		}
		dp[i][child[i]] = 1;
	}


	cout << dp[0][K] % mod << endl;
	cin >> N;
}
0