結果

問題 No.196 典型DP (1)
ユーザー mamekinmamekin
提出日時 2015-07-20 21:51:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,221 bytes
コンパイル時間 1,488 ms
コンパイル使用メモリ 94,496 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-22 20:46:51
合計ジャッジ時間 2,612 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 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
4,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 12 ms
4,380 KB
testcase_32 AC 12 ms
4,380 KB
testcase_33 AC 12 ms
4,380 KB
testcase_34 AC 12 ms
4,376 KB
testcase_35 AC 12 ms
4,380 KB
testcase_36 AC 11 ms
4,380 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const int MOD = 1000000007;

int solve(const vector<vector<int> >& edges, int curr, vector<long long>& ans)
{
    int n = 1;
    ans.assign(n+1, 0);
    ans[0] = 1;

    for(int next : edges[curr]){
        vector<long long> x;
        int m = solve(edges, next, x);

        vector<long long> y(n+m+1, 0);
        for(int i=0; i<=n; ++i){
            for(int j=0; j<=m; ++j){
                y[i+j] += ans[i] * x[j];
                y[i+j] %= MOD;
            }
        }
        ans.swap(y);
        n += m;
    }
    ++ ans[n];

    return n;
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<vector<int> > edges(n);
    for(int i=0; i<n-1; ++i){
        int a, b;
        cin >> a >> b;
        edges[a].push_back(b);
    }

    vector<long long> ans;
    solve(edges, 0, ans);
    cout << ans[k] << endl;

    return 0;
}
0