結果

問題 No.196 典型DP (1)
ユーザー face4face4
提出日時 2019-11-25 10:24:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 951 bytes
コンパイル時間 689 ms
コンパイル使用メモリ 70,528 KB
実行使用メモリ 17,664 KB
最終ジャッジ日時 2024-10-12 21:12:51
合計ジャッジ時間 2,834 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
vector<int> v[2001];
int dp[2001][2001] = {}, child[2001] = {};
void dfs(int x, int p){
child[x] = 1;
for(int next : v[x]){
if(next == p) continue;
dfs(next, x);
child[x] += child[next];
}
}
void dfs2(int x, int p){
dp[x][0] = 1;
for(int next : v[x]){
if(next == p) continue;
dfs2(next, x);
for(int i = child[x]-child[next]; i >= 0; i--){
for(int j = child[next]; j > 0; j--){
(dp[x][i+j] += (ll)dp[x][i]*dp[next][j]%mod) %= mod;
}
}
}
dp[x][child[x]] = 1;
}
int main(){
int n, k;
cin >> n >> k;
for(int i = 0; i < n-1; i++){
int a, b;
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
dfs(0, -1);
dfs2(0, -1);
cout << dp[0][k] << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0