結果

問題 No.196 典型DP (1)
ユーザー nxterunxteru
提出日時 2018-07-05 23:07:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 73,532 KB
実行使用メモリ 406,920 KB
最終ジャッジ日時 2023-09-13 18:02:33
合計ジャッジ時間 5,680 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
10,912 KB
testcase_01 WA -
testcase_02 AC 3 ms
6,476 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 4 ms
6,660 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 3 ms
6,512 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 3 ms
6,796 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 MLE -
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 <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;
    dp[v][1]=1;
    for(int i=0;i<g[v][i];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];
        }
    }
}
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