結果

問題 No.196 典型DP (1)
ユーザー no15_renneno15_renne
提出日時 2015-04-27 00:22:50
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,557 bytes
コンパイル時間 704 ms
コンパイル使用メモリ 76,344 KB
実行使用メモリ 8,768 KB
最終ジャッジ日時 2023-09-18 12:26:31
合計ジャッジ時間 8,019 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
8,768 KB
testcase_01 AC 11 ms
4,376 KB
testcase_02 AC 11 ms
4,376 KB
testcase_03 AC 22 ms
4,376 KB
testcase_04 AC 31 ms
4,384 KB
testcase_05 AC 42 ms
4,376 KB
testcase_06 AC 51 ms
4,380 KB
testcase_07 AC 61 ms
4,380 KB
testcase_08 AC 71 ms
4,376 KB
testcase_09 AC 80 ms
4,384 KB
testcase_10 AC 199 ms
4,380 KB
testcase_11 AC 404 ms
4,380 KB
testcase_12 AC 582 ms
4,376 KB
testcase_13 AC 780 ms
4,428 KB
testcase_14 AC 940 ms
5,024 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef vector<int> vi;

const int INF = 1e9;
const int MOD = 1e9+7;

ll dp[2600][2600];

void dfs(int pre, int v, vector<vi> &g){
    dp[v][0] = 1;
    FOR(e, g[v]){
        int w = *e;
        if(w == pre) continue;
        dfs(v, w, g);

        RREP(i, 2500){
            RREP(j, 2500){
                if(i + j >= 2500) continue;
                if(!j) continue;
                (dp[v][i+j] += dp[v][i] * dp[w][j]) %= MOD;   
            }
        }

    }
    RREP(i, 2500){
        if(dp[v][i]){
            dp[v][i+1] = 1;
            break;
        }
    }
    return;
}

int main(void){
    int n, k;
    cin >> n >> k;
    vector<vi> g(n);
    REP(i, n-1){
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(-1, 0, g);
/*
    REP(i, n){
        REP(j, n){
            cout << dp[i][j] << ":";
        }cout << endl;
    }cout << endl;
*/
    cout << dp[0][k] << endl;

    return 0;
}
0