結果
問題 | No.196 典型DP (1) |
ユーザー | cubinglover |
提出日時 | 2022-11-26 19:01:16 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,121 bytes |
コンパイル時間 | 2,629 ms |
コンパイル使用メモリ | 206,684 KB |
実行使用メモリ | 41,632 KB |
最終ジャッジ日時 | 2024-04-14 05:41:53 |
合計ジャッジ時間 | 12,802 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 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,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 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 | 3 ms
6,948 KB |
testcase_12 | AC | 3 ms
6,944 KB |
testcase_13 | AC | 3 ms
6,940 KB |
testcase_14 | AC | 3 ms
6,944 KB |
testcase_15 | AC | 13 ms
8,832 KB |
testcase_16 | AC | 33 ms
14,208 KB |
testcase_17 | AC | 68 ms
19,968 KB |
testcase_18 | AC | 195 ms
26,112 KB |
testcase_19 | AC | 206 ms
29,056 KB |
testcase_20 | AC | 274 ms
34,816 KB |
testcase_21 | AC | 305 ms
34,688 KB |
testcase_22 | AC | 260 ms
34,816 KB |
testcase_23 | AC | 1,755 ms
34,816 KB |
testcase_24 | AC | 1,224 ms
34,816 KB |
testcase_25 | AC | 1,222 ms
34,816 KB |
testcase_26 | TLE | - |
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 <bits/stdc++.h> using namespace std; #define repl(i, l, r) for (int i = (l); i < (int)(r); ++i) #define rep(i, n) repl(i, 0, n) #define CST(x) cout << fixed << setprecision(x) #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() using ll = long long; constexpr ll MOD = 1e9 + 7; constexpr int inf = 1e9 + 10; constexpr ll INF = (ll)4e18 + 10; constexpr int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}; constexpr int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0}; const double PI = acos(-1); template <typename T> using MaxHeap = priority_queue<T>; template <typename T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; template <typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template <typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } template <typename T> inline void yn(const T &a) { ((a) ? (cout << "Yes" << endl) : (cout << "No" << endl)); } template <typename T> inline void YN(const T &a) { ((a) ? (cout << "YES" << endl) : (cout << "NO" << endl)); } int main() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<vector<int>> G(n); rep(i, n - 1) { int a, b; cin >> a >> b; G[a].emplace_back(b), G[b].emplace_back(a); } vector dp(n, vector(2005, 0ll)); auto f = [&G, &dp](auto self, const auto &v, const auto &p) -> int { dp[v][0] = 1; int res = 1; for (const auto &to : G[v]) { if (to == p) continue; res += self(self, to, v); } for (const auto &to : G[v]) { if (to == p) continue; for (int i = res - 1; i > 0; --i) { ll x = 0; rep(j, i + 1) { if (i + j == 0) continue; x += dp[v][i - j] * dp[to][j]; x %= MOD; } dp[v][i] = x; } } dp[v][res] = 1; return res; }; f(f, 0, -1); cout << dp[0][k] << endl; return 0; }