結果

問題 No.196 典型DP (1)
ユーザー beetbeet
提出日時 2018-06-21 19:40:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 844 bytes
コンパイル時間 1,536 ms
コンパイル使用メモリ 173,492 KB
実行使用メモリ 27,668 KB
最終ジャッジ日時 2023-09-13 07:37:56
合計ジャッジ時間 7,733 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,760 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 13 ms
4,380 KB
testcase_18 AC 42 ms
4,380 KB
testcase_19 AC 45 ms
4,376 KB
testcase_20 AC 39 ms
4,380 KB
testcase_21 AC 57 ms
4,380 KB
testcase_22 AC 64 ms
4,380 KB
testcase_23 AC 838 ms
11,136 KB
testcase_24 AC 521 ms
8,544 KB
testcase_25 AC 498 ms
8,048 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;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n,k;
  cin>>n>>k;
  vector<vector<Int> > G(n);
  for(Int i=1;i<n;i++){
    Int x,y;
    cin>>x>>y;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  const Int MOD = 1e9+7;
  vector<vector<Int> > dp(n);
  vector<Int> sz(n,1);
  function<void(Int,Int)> dfs=
    [&](Int v,Int p){
      for(Int u:G[v]){
	if(u==p) continue;
	dfs(u,v);
	sz[v]+=sz[u];
      }
      dp[v].assign(sz[v]+1,0);
      dp[v][0]=1;
      for(Int u:G[v]){
	if(u==p) continue;
	vector<Int> nx(sz[v]+1,0);
	for(Int i=0;i<=sz[v];i++)
	  for(Int j=0;j<=sz[u];j++)
	    if(i+j<=sz[v]) nx[i+j]+=dp[v][i]*dp[u][j]%MOD;
	for(Int i=0;i<=sz[v];i++) nx[i]%=MOD;
	swap(dp[v],nx);
      }
      dp[v][sz[v]]=1;
    };
  dfs(0,-1);
  cout<<dp[0][k]<<endl;
  return 0;
}
0