結果

問題 No.196 典型DP (1)
ユーザー 沙耶花沙耶花
提出日時 2021-11-04 06:59:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 401 ms / 2,000 ms
コード長 1,073 bytes
コンパイル時間 4,466 ms
コンパイル使用メモリ 265,636 KB
実行使用メモリ 223,104 KB
最終ジャッジ日時 2024-04-22 03:38:56
合計ジャッジ時間 11,117 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 13 ms
5,376 KB
testcase_17 AC 23 ms
5,376 KB
testcase_18 AC 41 ms
6,912 KB
testcase_19 AC 54 ms
7,296 KB
testcase_20 AC 72 ms
6,528 KB
testcase_21 AC 78 ms
7,040 KB
testcase_22 AC 73 ms
7,424 KB
testcase_23 AC 204 ms
83,328 KB
testcase_24 AC 155 ms
58,624 KB
testcase_25 AC 148 ms
51,328 KB
testcase_26 AC 398 ms
223,104 KB
testcase_27 AC 401 ms
222,976 KB
testcase_28 AC 400 ms
223,104 KB
testcase_29 AC 398 ms
223,104 KB
testcase_30 AC 397 ms
223,104 KB
testcase_31 AC 297 ms
5,376 KB
testcase_32 AC 298 ms
5,376 KB
testcase_33 AC 299 ms
5,376 KB
testcase_34 AC 298 ms
5,376 KB
testcase_35 AC 301 ms
5,376 KB
testcase_36 AC 275 ms
5,376 KB
testcase_37 AC 84 ms
5,376 KB
testcase_38 AC 279 ms
5,376 KB
testcase_39 AC 227 ms
5,376 KB
testcase_40 AC 306 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000002

int N,K;
vector<vector<int>> E;
vector<vector<vector<mint>>> dp;

void dfs(int cur,int p){
	dp[cur].resize(2,vector<mint>(2,0));
	dp[cur][0][0] = 1;
	rep(i,E[cur].size()){
		int to = E[cur][i];
		if(to==p)continue;
		dfs(to,cur);
		vector ndp(dp[cur].size()+dp[to].size(),vector<mint>(2,0));
		
		rep(j,dp[cur].size()){
			rep(k,2){
				rep(jj,dp[to].size()){
					rep(kk,2){
						ndp[j+jj][k|kk] += dp[cur][j][k] * dp[to][jj][kk];
					}
				}
			}
		}
		swap(dp[cur],ndp);
	}
	rep(i,dp[cur].size()){
		dp[cur][i][1] += dp[cur][i][0];
	}
	for(int i=dp[cur].size()-1;i>=1;i--){
		dp[cur][i][0] = dp[cur][i-1][0];
	}
	dp[cur][0][0] = 0;
}

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