結果

問題 No.196 典型DP (1)
ユーザー cormorancormoran
提出日時 2016-02-29 01:18:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,259 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 68,260 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 18:58:14
合計ジャッジ時間 1,713 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 4 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 7 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 6 ms
4,348 KB
testcase_29 AC 7 ms
4,348 KB
testcase_30 AC 7 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 7 ms
4,348 KB
testcase_33 AC 9 ms
4,348 KB
testcase_34 AC 11 ms
4,348 KB
testcase_35 AC 11 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 5 ms
4,348 KB
testcase_38 AC 9 ms
4,348 KB
testcase_39 AC 9 ms
4,348 KB
testcase_40 AC 12 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 1 ms
4,348 KB
testcase_43 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
#include<string>
using namespace std;

typedef long long ll;
typedef ll int__;
#define rep(i,j) for(int__ i=0;i<(int__)(j);i++)

using EdgeList = vector<vector<int>>;
const ll MOD = 1000000007;
EdgeList E;
int K;

#define maxIndex(x) (x.size() -1)

vector<ll> convolution(const vector<ll> &A, const vector<ll> &B){
    int max_value = maxIndex(A) + maxIndex(B);
    vector<ll> ret( min(K, max_value) + 1 );
    rep(i, A.size()){
        rep(j, B.size()){
            if(i + j <= K){
                ret[i+j] += A[i] * B[j];
                ret[i+j] %= MOD;
            }
        }
    }
    return ret;
}

vector<ll> dfs(int now, int pre){
    vector<ll> ret = {1};
    for(int nxt : E[now]){
        if(nxt != pre){
            ret = convolution(ret, dfs(nxt, now));
        }
    }
    if(maxIndex(ret) < K) ret.push_back(1);
    return ret;
}

bool solve(){
    int N; cin >> N >> K;
    E.resize(N);
    rep(i,N-1){
        int a, b; cin >> a >> b; 
        E[a].push_back(b);
        E[b].push_back(a);
    }
    vector<ll> ans = dfs(0, -1);
    cout << ( maxIndex(ans) >= K ? ans[K] : 0 )<< endl;
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}
0