結果

問題 No.196 典型DP (1)
ユーザー nxterunxteru
提出日時 2018-07-05 23:14:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 835 bytes
コンパイル時間 569 ms
コンパイル使用メモリ 73,784 KB
実行使用メモリ 68,740 KB
最終ジャッジ日時 2023-09-13 18:03:00
合計ジャッジ時間 2,866 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,740 KB
testcase_01 AC 3 ms
6,484 KB
testcase_02 AC 3 ms
6,572 KB
testcase_03 AC 3 ms
6,420 KB
testcase_04 AC 3 ms
6,452 KB
testcase_05 AC 3 ms
6,508 KB
testcase_06 AC 4 ms
6,648 KB
testcase_07 AC 3 ms
6,496 KB
testcase_08 AC 3 ms
6,452 KB
testcase_09 AC 3 ms
6,648 KB
testcase_10 AC 3 ms
6,592 KB
testcase_11 AC 3 ms
6,864 KB
testcase_12 AC 3 ms
6,776 KB
testcase_13 AC 4 ms
7,248 KB
testcase_14 AC 4 ms
7,104 KB
testcase_15 AC 6 ms
11,516 KB
testcase_16 AC 8 ms
17,696 KB
testcase_17 AC 11 ms
24,080 KB
testcase_18 AC 16 ms
30,456 KB
testcase_19 AC 16 ms
32,504 KB
testcase_20 AC 18 ms
36,316 KB
testcase_21 AC 18 ms
36,088 KB
testcase_22 AC 18 ms
36,064 KB
testcase_23 AC 31 ms
49,780 KB
testcase_24 AC 27 ms
44,552 KB
testcase_25 AC 28 ms
44,596 KB
testcase_26 AC 43 ms
67,620 KB
testcase_27 AC 43 ms
67,768 KB
testcase_28 AC 45 ms
68,352 KB
testcase_29 AC 48 ms
68,740 KB
testcase_30 AC 48 ms
68,684 KB
testcase_31 AC 24 ms
35,888 KB
testcase_32 AC 24 ms
35,688 KB
testcase_33 AC 24 ms
35,808 KB
testcase_34 AC 24 ms
35,748 KB
testcase_35 AC 25 ms
35,708 KB
testcase_36 AC 23 ms
35,696 KB
testcase_37 AC 19 ms
36,272 KB
testcase_38 AC 24 ms
35,756 KB
testcase_39 AC 23 ms
36,052 KB
testcase_40 AC 24 ms
35,936 KB
testcase_41 AC 3 ms
6,520 KB
testcase_42 AC 3 ms
6,460 KB
testcase_43 AC 3 ms
6,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define M 1000000007
int n,k,s[2005];
vector<int>g[100005];
ll dp[2005][2005];
void dfs(int v,int p){
    s[v]=1;
    dp[v][0]=1;
    for(int i=0;i<g[v].size();i++){
        int u=g[v][i];
        if(u!=p){
            dfs(u,v);
            ll r[2005]={};
            for(int i=0;i<s[v];i++){
                for(int j=0;j<=s[u];j++){
                    r[i+j]=(r[i+j]+dp[v][i]*dp[u][j]%M)%M;
                }
            }
            for(int i=0;i<=k;i++)dp[v][i]=r[i];
            s[v]+=s[u];
        }
    }
    dp[v][s[v]]=1;
}
int main(void){
    cin>>n>>k;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0,-1);
    cout<<dp[0][k]<<endl;
}
0