結果
問題 | No.196 典型DP (1) |
ユーザー | Div9851 |
提出日時 | 2017-10-08 00:01:17 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 971 bytes |
コンパイル時間 | 1,336 ms |
コンパイル使用メモリ | 162,384 KB |
実行使用メモリ | 40,984 KB |
最終ジャッジ日時 | 2024-04-28 12:54:31 |
合計ジャッジ時間 | 7,478 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
12,192 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 3 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 8 ms
9,876 KB |
testcase_16 | AC | 18 ms
14,232 KB |
testcase_17 | AC | 29 ms
19,888 KB |
testcase_18 | AC | 80 ms
24,640 KB |
testcase_19 | AC | 44 ms
10,240 KB |
testcase_20 | AC | 10 ms
11,648 KB |
testcase_21 | AC | 17 ms
11,648 KB |
testcase_22 | AC | 10 ms
11,648 KB |
testcase_23 | AC | 494 ms
17,024 KB |
testcase_24 | AC | 39 ms
14,976 KB |
testcase_25 | AC | 1,184 ms
14,976 KB |
testcase_26 | AC | 10 ms
17,536 KB |
testcase_27 | AC | 264 ms
20,352 KB |
testcase_28 | TLE | - |
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 | -- | - |
ソースコード
#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define ALL(v) (v).begin(),(v).end() #define MP(a,b) make_pair(a,b) typedef long long LL; typedef pair<int, int> PI; typedef vector<int> VI; const LL MOD = 1000000007LL; vector<int> G[2000]; LL dp[2000][2001]; int tree[2000]; int N, K; void cnt(int v, int par) { tree[v] = 1; rep(i, G[v].size()) { int to = G[v][i]; if (to == par) continue; cnt(to, v); tree[v] += tree[to]; } } void dfs(int v, int par) { dp[v][0] = 1; rep(i, G[v].size()) { int to = G[v][i]; if (to == par) continue; dfs(to, v); for (int j = min(K,tree[v]); j >= 1; j--) { for (int k = 1; k <= j; k++) { LL t = (dp[v][j - k] * dp[to][k]) % MOD; (dp[v][j] += t) %= MOD; } } } (dp[v][tree[v]] += 1) %= MOD; } int main() { cin >> N >> K; rep(i, N - 1) { int a, b; cin >> a >> b; G[a].push_back(b); G[b].push_back(a); } cnt(0, -1); dfs(0, -1); cout << dp[0][K] << endl; }