結果

問題 No.196 典型DP (1)
ユーザー Kiona1018Kiona1018
提出日時 2019-09-29 12:59:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,315 bytes
コンパイル時間 1,432 ms
コンパイル使用メモリ 168,720 KB
実行使用メモリ 34,972 KB
最終ジャッジ日時 2023-07-26 17:41:05
合計ジャッジ時間 3,466 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,444 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 17 ms
34,972 KB
testcase_27 AC 19 ms
34,932 KB
testcase_28 AC 23 ms
34,916 KB
testcase_29 AC 25 ms
34,916 KB
testcase_30 AC 25 ms
34,904 KB
testcase_31 AC 12 ms
33,132 KB
testcase_32 AC 17 ms
32,832 KB
testcase_33 AC 18 ms
32,816 KB
testcase_34 AC 20 ms
32,964 KB
testcase_35 AC 20 ms
32,808 KB
testcase_36 AC 12 ms
32,928 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 19 ms
33,104 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
const int MAX_N = 2002;
const ll MOD = 1000000007;

vector<int> graph[MAX_N];
ll dp[MAX_N][MAX_N];
int num[MAX_N];
int k;

void dfs(int root, int par)
{

    dp[root][0] = 1;
    // dp[root][1] = 1;
    num[root] = 1;
    for (auto ch: graph[root])
    if (ch != par)
    {
        dfs(ch, root);

        vector<int> dp_now(MAX_N, 0);
        rep(i, 0, num[ch]+1)
        {
            rep(j, 0, num[root]+1)
            {
                if (i+j > k) break;
                dp_now[i+j] += dp[root][j] * dp[ch][i];
                dp_now[i+j] %= MOD;
                // cout << root << ' ' << i << ' ' << j << " : "<< dp[root][j] << ' ' << dp[ch][i] << endl;
            }
        }
        
        num[root] += num[ch];
        rep(i, 0, MAX_N) dp[root][i] = dp_now[i];
    }
    dp[root][num[root]] = 1;
    // cout << root << ' ' << dp[root][0] << ' ' << dp[root][1] << endl;
}

int main()
{
    int n;
    cin >> n >> k;

    rep(i, 0, n-1)
    {
        int a, b;
        cin >> a >> b;
        // --a, --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs(0, -1);
    cout << dp[0][k] << endl;
    return 0;
}
0