結果

問題 No.196 典型DP (1)
ユーザー kimiyukikimiyuki
提出日時 2017-01-11 16:03:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,363 bytes
コンパイル時間 999 ms
コンパイル使用メモリ 79,616 KB
実行使用メモリ 18,516 KB
最終ジャッジ日時 2023-08-23 08:28:47
合計ジャッジ時間 9,475 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 41 ms
4,376 KB
testcase_16 AC 298 ms
5,356 KB
testcase_17 AC 1,053 ms
8,016 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
vector<int> merge(vector<int> const & a, vector<int> const & b) {
    int n = a.size();
    vector<int> c(n);
    repeat (i,n) {
        ll acc = 0;
        repeat (j,i+1) {
            int k = i - j;
            acc += a[j] *(ll) b[k] % mod;
        }
        c[i] = acc % mod;
    }
    return c;
}
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);
    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];
            dp[i] = merge(dp[i], dp[j]);
        }
        dp[i][size[i]] = 1;
    };
    go(0, -1);
    cout << dp[0][k] << endl;
    return 0;
}
0