結果
| 問題 |
No.196 典型DP (1)
|
| コンテスト | |
| ユーザー |
pyonth
|
| 提出日時 | 2020-12-03 22:18:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,605 bytes |
| コンパイル時間 | 2,546 ms |
| コンパイル使用メモリ | 203,108 KB |
| 最終ジャッジ日時 | 2025-01-16 14:47:52 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 TLE * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
constexpr ll MOD = 1000000007;
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};
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
cin.tie(0);
cout.tie(0);
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].push_back(b);
G[b].push_back(a);
}
vector<int> s(n);
vector<vector<ll>> dp(n, vector(n + 1, 0LL));
auto dfs = [&](auto self, int v, int pre) -> void {
dp[v][0] = 1;
for (auto nv : G[v]) {
if (nv == pre) continue;
self(self, nv, v);
vector ndp(n + 1, 0LL);
rep(i, n) {
rep(j, n) {
if (dp[v][i] and dp[nv][j])
ndp[i + j] = (ndp[i + j] + dp[v][i] * dp[nv][j] % MOD) % MOD;
}
}
dp[v] = ndp;
s[v] += s[nv];
}
s[v]++;
dp[v][s[v]]++;
};
dfs(dfs, 0, -1);
cout << dp[0][k] << endl;
return 0;
}
pyonth