結果

問題 No.196 典型DP (1)
ユーザー akusyounin2412akusyounin2412
提出日時 2019-02-05 23:53:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 2,729 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 129,420 KB
実行使用メモリ 55,012 KB
最終ジャッジ日時 2023-08-31 00:00:37
合計ジャッジ時間 4,738 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,452 KB
testcase_01 AC 2 ms
7,416 KB
testcase_02 AC 2 ms
7,656 KB
testcase_03 AC 3 ms
7,500 KB
testcase_04 AC 2 ms
7,468 KB
testcase_05 AC 2 ms
7,460 KB
testcase_06 AC 2 ms
7,516 KB
testcase_07 AC 2 ms
7,500 KB
testcase_08 AC 3 ms
7,592 KB
testcase_09 AC 3 ms
7,520 KB
testcase_10 AC 2 ms
7,424 KB
testcase_11 AC 2 ms
7,464 KB
testcase_12 AC 3 ms
7,488 KB
testcase_13 AC 3 ms
9,620 KB
testcase_14 AC 3 ms
9,656 KB
testcase_15 AC 5 ms
15,804 KB
testcase_16 AC 11 ms
23,912 KB
testcase_17 AC 20 ms
32,420 KB
testcase_18 AC 32 ms
40,416 KB
testcase_19 AC 40 ms
46,724 KB
testcase_20 AC 55 ms
54,704 KB
testcase_21 AC 55 ms
54,988 KB
testcase_22 AC 55 ms
54,800 KB
testcase_23 AC 51 ms
54,820 KB
testcase_24 AC 53 ms
54,856 KB
testcase_25 AC 54 ms
54,816 KB
testcase_26 AC 37 ms
54,952 KB
testcase_27 AC 37 ms
54,984 KB
testcase_28 AC 36 ms
54,940 KB
testcase_29 AC 37 ms
54,988 KB
testcase_30 AC 37 ms
55,012 KB
testcase_31 AC 103 ms
54,756 KB
testcase_32 AC 102 ms
54,712 KB
testcase_33 AC 103 ms
54,724 KB
testcase_34 AC 103 ms
54,764 KB
testcase_35 AC 103 ms
54,916 KB
testcase_36 AC 98 ms
54,768 KB
testcase_37 AC 57 ms
54,868 KB
testcase_38 AC 97 ms
54,916 KB
testcase_39 AC 88 ms
54,684 KB
testcase_40 AC 101 ms
54,680 KB
testcase_41 AC 2 ms
7,404 KB
testcase_42 AC 2 ms
7,468 KB
testcase_43 AC 2 ms
7,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans,dp[3000][3000], a[330020], b[330000],sub[3000];
string str, ss;
bool f[220000];
char c[4000][4000];
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>vec,rvec;
vector<edge>ed;
vector<LL>v;
map<string, LL>ma;
set<LL>st;

void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
void sub_cnt(int cur,int par) {
	rep(i, vec[cur].size()) {
		if (vec[cur][i].to == par)continue;
		sub_cnt(vec[cur][i].to, cur);
		sub[cur] += sub[vec[cur][i].to];
	}
	sub[cur]++;
}
void dfs(int cur,int par) {
	rep(i, vec[cur].size()) {
		LL v = vec[cur][i].to;
		if (v == par)continue;
		dfs(v,cur);
		vector<LL>table(sub[cur]+1, 0);
		rep(j, sub[cur] - sub[v]) 
			rep(l, sub[v] + 1) 
				(table[j + l] += dp[cur][j] * dp[v][l]) %= MOD;
		rep(j, sub[cur])dp[cur][j] = table[j];
	}
	dp[cur][sub[cur]] = 1;
}
int main() {
	cin >> n >> k;
	vec.resize(n);
	rep(i, n-1) {
		LL x, y;
		cin >> x >> y;
		vec[x].push_back(Edge{ y,0 });
		vec[y].push_back(Edge{ x,0 });
	}
	sub_cnt(0, -1);
	rep(i, n)dp[i][0] = 1;
	dfs(0,-1);
	cout << dp[0][k] << endl;
	return 0;
}
0