結果

問題 No.196 典型DP (1)
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-04-23 15:01:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,573 bytes
コンパイル時間 1,805 ms
コンパイル使用メモリ 177,144 KB
実行使用メモリ 97,952 KB
最終ジャッジ日時 2023-09-29 02:03:43
合計ジャッジ時間 9,819 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 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 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 366 ms
97,848 KB
testcase_27 AC 363 ms
97,928 KB
testcase_28 AC 365 ms
97,952 KB
testcase_29 AC 365 ms
97,920 KB
testcase_30 AC 366 ms
97,888 KB
testcase_31 AC 264 ms
4,376 KB
testcase_32 AC 263 ms
4,380 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 268 ms
4,384 KB
testcase_36 AC 250 ms
4,380 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 260 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
int modpow(int a, long long b) { int ret = 1; while (b > 0) { if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1; } return ret; }
int modinv(int a) { return modpow(a, mod - 2); }
//-----------------------------------------------------------------------------------
int N, K;
vector<int> E[2010];
//-----------------------------------------------------------------------------------
int cnt[2010]; map<int,int> dp[2010];
void merge(int cu, int to) { // dp[cu] = dp[cu] + dp[to]
    map<int, int> cnt;
    for (auto p : dp[cu]) for (auto q : dp[to]) {
        cnt[p.first + q.first] += mul(p.second, q.second);
    }
    dp[cu] = cnt;
}
void dfs(int cu, int pa = -1) {
    dp[cu][0] = 1;

    cnt[cu] = 1;
    for (int to : E[cu]) if (pa != to) {
        dfs(to, cu);
        cnt[cu] += cnt[to];

        merge(cu, to);
    }

    dp[cu][cnt[cu]] = 1;
}
//-----------------------------------------------------------------------------------
int main() {
    cin >> N >> K;
    rep(i, 0, N - 1) {
        int a, b; scanf("%d%d", &a, &b);
        E[a].push_back(b); E[b].push_back(a);
    }

    dfs(0);
    printf("%d\n", dp[0][K]);
}
0