結果

問題 No.196 典型DP (1)
ユーザー sugim48sugim48
提出日時 2015-04-26 22:32:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,437 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 95,756 KB
実行使用メモリ 12,028 KB
最終ジャッジ日時 2023-09-18 12:04:10
合計ジャッジ時間 3,286 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,504 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 16 ms
4,376 KB
testcase_19 AC 18 ms
4,376 KB
testcase_20 AC 26 ms
4,380 KB
testcase_21 AC 26 ms
4,380 KB
testcase_22 AC 25 ms
4,376 KB
testcase_23 AC 38 ms
7,112 KB
testcase_24 AC 34 ms
6,060 KB
testcase_25 AC 33 ms
5,920 KB
testcase_26 AC 54 ms
11,692 KB
testcase_27 AC 54 ms
11,800 KB
testcase_28 AC 54 ms
11,752 KB
testcase_29 AC 54 ms
12,028 KB
testcase_30 AC 54 ms
11,696 KB
testcase_31 AC 52 ms
4,376 KB
testcase_32 AC 52 ms
4,376 KB
testcase_33 AC 52 ms
4,376 KB
testcase_34 AC 52 ms
4,376 KB
testcase_35 AC 52 ms
4,380 KB
testcase_36 AC 49 ms
4,380 KB
testcase_37 AC 26 ms
4,376 KB
testcase_38 AC 50 ms
4,376 KB
testcase_39 AC 44 ms
4,380 KB
testcase_40 AC 51 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <fstream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

int INF = INT_MAX / 10;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

void f(int u, int p, vector<vector<int> >& G, vector<vector<int> >& a) {
	a[u] = vector<int>(2, 0);
	a[u][1] = 1;
	for (int i = 0; i < G[u].size(); i++) {
		int v = G[u][i];
		if (v == p) continue;
		f(v, u, G, a);
		int n = a[u].size(), m = a[v].size();
		vector<int> b(min(2001, n + m - 1));
		for (int x = 0; x < n; x++)
			for (int y = 0; y < m; y++)
				if (x + y <= 2000)
					b[x + y] = (b[x + y] + (ll)a[u][x] * a[v][y]) % MOD;
		a[u] = b;
	}
	a[u][0] = (a[u][0] + 1) % MOD;
}

int main() {
	int N, K; cin >> N >> K;
	vector<vector<int> > G(N);
	for (int i = 0; i < N - 1; i++) {
		int a, b; cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<vector<int> > a(N);
	f(0, -1, G, a);
	cout << a[0][N - K] << endl;
}
0