結果

問題 No.196 典型DP (1)
ユーザー tsutajtsutaj
提出日時 2018-06-09 12:43:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,012 bytes
コンパイル時間 449 ms
コンパイル使用メモリ 53,672 KB
実行使用メモリ 32,480 KB
最終ジャッジ日時 2023-09-13 01:47:19
合計ジャッジ時間 2,865 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
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 3 ms
7,212 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 12 ms
32,452 KB
testcase_32 AC 13 ms
32,456 KB
testcase_33 AC 12 ms
32,404 KB
testcase_34 AC 12 ms
32,480 KB
testcase_35 AC 13 ms
32,448 KB
testcase_36 AC 12 ms
32,424 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
using Graph = vector< vector<int> >;

const long long int MOD = 1000000007LL;
int N, K, num[2010];
long long int dp[2010][2010];

void dfs(Graph &G, int cur) {
    num[cur] = 1;
    for(auto to : G[cur]) {
        dfs(G, to);
        num[cur] += num[to];
    }
}

void solve(Graph &G, int cur) {
    // 全く塗らない、全部塗る
    dp[cur][0] = 1;
    int sum = 0;
    for(auto to : G[cur]) {
        // cur は塗らない
        solve(G, to);
        for(int k=sum; k>=0; k--) {
            for(int pt=num[to]; pt>=1; pt--) {
                (dp[cur][k+pt] += dp[cur][k] * dp[to][pt]) %= MOD;
            }
        }
        sum += num[to];
    }
    dp[cur][ num[cur] ] = 1;
}

int main() {
    scanf("%d%d", &N, &K);

    Graph G(N);
    for(int i=0; i<N-1; i++) {
        int u, v; scanf("%d%d", &u, &v);
        G[u].push_back(v);
    }

    dfs(G, 0);
    solve(G, 0);

    printf("%lld\n", dp[0][K]);
    return 0;
}
0