結果

問題 No.196 典型DP (1)
ユーザー kimiyukikimiyuki
提出日時 2017-01-11 16:14:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,476 bytes
コンパイル時間 914 ms
コンパイル使用メモリ 78,728 KB
実行使用メモリ 19,596 KB
最終ジャッジ日時 2023-08-23 08:58:51
合計ジャッジ時間 35,960 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 10 ms
5,484 KB
testcase_17 AC 19 ms
8,144 KB
testcase_18 AC 51 ms
11,908 KB
testcase_19 AC 62 ms
14,092 KB
testcase_20 AC 46 ms
19,248 KB
testcase_21 AC 72 ms
19,248 KB
testcase_22 AC 64 ms
19,236 KB
testcase_23 AC 603 ms
19,284 KB
testcase_24 AC 399 ms
19,352 KB
testcase_25 AC 394 ms
19,436 KB
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
testcase_37 AC 165 ms
19,188 KB
testcase_38 TLE -
testcase_39 AC 1,675 ms
19,252 KB
testcase_40 TLE -
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <functional>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using ll = long long;
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
const int mod = 1e9+7;
void merge(vector<int> const & a, vector<int> const & b, vector<int> & c, int size) {
    int n = c.size();
    repeat (i,n) {
        ll acc = 0;
        if (i < size) {
            repeat (j,i+1) {
                int k = i - j;
                acc += a[j] *(ll) b[k] % mod;
            }
            acc %= mod;
        }
        c[i] = acc;
    }
}
int main() {
    int n, k; cin >> n >> k;
    vector<vector<int> > g(n);
    repeat (i,n-1) {
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<vector<int> > dp = vectors(n, n+1, int());
    vector<int> size(n);
    vector<int> acc(n+1);
    function<void (int, int)> go = [&](int i, int parent) {
        size[i] = 1;
        dp[i][0] = 1;
        for (int j : g[i]) if (j != parent) {
            go(j, i);
            size[i] += size[j];
            merge(dp[i], dp[j], acc, size[i]);
            dp[i].swap(acc);
        }
        dp[i][size[i]] = 1;
    };
    go(0, -1);
    cout << dp[0][k] << endl;
    return 0;
}
0