結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,756 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 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,380 KB
testcase_14 AC 1 ms
4,376 KB
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 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;
	swap(dp[v],nx);
	for(Int i=0;i<=sz[v];i++) nx[i]%=MOD;
      }
      dp[v][sz[v]]=1;
    };
  dfs(0,-1);
  cout<<dp[0][k]<<endl;
  return 0;
}
0