結果

問題 No.196 典型DP (1)
ユーザー heno239heno239
提出日時 2019-02-26 11:45:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 859 bytes
コンパイル時間 1,933 ms
コンパイル使用メモリ 173,200 KB
実行使用メモリ 20,252 KB
最終ジャッジ日時 2023-09-02 17:49:01
合計ジャッジ時間 4,167 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
vector<int> G[2000];bool used[2000];
int k;
vector<ll> dp[2000];
void merge(int i,int j){
  int l1=dp[i].size();
  int l2=dp[j].size();
  vector<ll> nex;nex.resize(l1+l2-1,0);
  rep(i1,l1){
   rep(i2,l2){
    nex[i1+i2]+=dp[i][i1]*dp[j][i2]%mod;
    nex[i1+i2]%=mod;
   }
  }
  dp[i]=nex;
}
void dfs(int id){
 used[id]=true;dp[id].resize(2,0);ll sum=1;
dp[id][0]=1;
 rep(j,G[id].size()){
  int to=G[id][j];
  if(used[to])continue;
  dfs(to);merge(id,to);
  int len=dp[to].size();
  sum=sum*dp[to][len-1]%mod;
 }
 int len=dp[id].size();
 dp[id][len-1]+=sum;dp[id][len-1]%=mod;
}
int main(){
  int n;cin>>n>>k;
  rep(i,n-1){
    int a,b;cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
 dfs(0);
 cout<<dp[0][k]<<endl;
}
0