結果
問題 | No.196 典型DP (1) |
ユーザー | veqcc |
提出日時 | 2019-02-21 20:15:11 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,437 bytes |
コンパイル時間 | 732 ms |
コンパイル使用メモリ | 96,592 KB |
実行使用メモリ | 50,384 KB |
最終ジャッジ日時 | 2024-04-30 22:10:42 |
合計ジャッジ時間 | 8,149 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
13,756 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 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,944 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 3 ms
6,944 KB |
testcase_15 | AC | 30 ms
8,356 KB |
testcase_16 | AC | 225 ms
14,296 KB |
testcase_17 | AC | 466 ms
22,272 KB |
testcase_18 | AC | 1,395 ms
27,812 KB |
testcase_19 | AC | 702 ms
29,192 KB |
testcase_20 | AC | 20 ms
33,108 KB |
testcase_21 | AC | 62 ms
33,128 KB |
testcase_22 | AC | 11 ms
32,980 KB |
testcase_23 | AC | 419 ms
38,836 KB |
testcase_24 | AC | 36 ms
34,012 KB |
testcase_25 | TLE | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
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 <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <string> #include <vector> #include <queue> #include <cmath> #include <stack> #include <set> #include <map> typedef long long ll; typedef unsigned int uint; using namespace std; const ll MOD = 1000000007LL; int n, K; vector <int> edge[2005]; ll dp[2005][2005]; // 頂点i以下のsubtreeにおいて、ちょうどj個の頂点を黒にする場合の数 int dfs(int cur, int par) { ll dp2[2][K+1]; // 子をx番目まで見たときに、頂点i以下でちょうどj個を黒にする場合の数 fill(dp2[0], dp2[1]+K+1, 0); dp2[0][0] = 1; int sz = 1; int x = 0, y = 1; for (int i = 0; i < edge[cur].size(); i++) { int child = edge[cur][i]; if (child == par) continue; sz += dfs(child, cur); for (int j = K; j >= 0; j--) { for (int k = 0; k <= K - j; k++) { (dp2[y][j+k] += dp2[x][k] * dp[child][j] % MOD) %= MOD; } } swap(x, y); fill(dp2[y], dp2[y]+K+1, 0); } for (int i = 0; i <= K; i++) dp[cur][i] = dp2[x][i]; if (sz <= K) (dp[cur][sz] += 1) %= MOD; return sz; } int main() { cin >> n >> K; for (int i = 1; i < n; i++) { int a, b; cin >> a >> b; edge[a].push_back(b); edge[b].push_back(a); } dfs(0, -1); cout << dp[0][K] << "\n"; return 0; }