結果
問題 | No.196 典型DP (1) |
ユーザー | Div9851 |
提出日時 | 2017-10-08 00:13:54 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,014 bytes |
コンパイル時間 | 1,147 ms |
コンパイル使用メモリ | 160,952 KB |
実行使用メモリ | 34,908 KB |
最終ジャッジ日時 | 2024-04-28 12:56:15 |
合計ジャッジ時間 | 6,985 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
13,760 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 3 ms
8,088 KB |
testcase_16 | AC | 7 ms
13,976 KB |
testcase_17 | AC | 11 ms
20,408 KB |
testcase_18 | AC | 30 ms
26,172 KB |
testcase_19 | AC | 18 ms
28,368 KB |
testcase_20 | AC | 10 ms
32,980 KB |
testcase_21 | AC | 12 ms
32,856 KB |
testcase_22 | AC | 9 ms
34,380 KB |
testcase_23 | AC | 337 ms
33,420 KB |
testcase_24 | AC | 28 ms
33,268 KB |
testcase_25 | AC | 670 ms
33,132 KB |
testcase_26 | AC | 10 ms
33,524 KB |
testcase_27 | AC | 239 ms
34,908 KB |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
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; int sum = 0; rep(i, G[v].size()) { int to = G[v][i]; if (to == par) continue; dfs(to, v); sum += tree[to]; for (int j = min(K,sum); j >= 1; j--) { for (int k = 1; k <= min(j,tree[to]); 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; }