結果

問題 No.196 典型DP (1)
ユーザー mamekinmamekin
提出日時 2015-07-20 21:51:40
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,221 bytes
コンパイル時間 813 ms
コンパイル使用メモリ 96,980 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-08 11:25:04
合計ジャッジ時間 2,428 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 27
権限があれば一括ダウンロードができます

ソースコード

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