結果

問題 No.196 典型DP (1)
ユーザー kurarrrkurarrr
提出日時 2018-02-21 10:40:45
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,450 bytes
コンパイル時間 1,701 ms
コンパイル使用メモリ 150,456 KB
実行使用メモリ 34,356 KB
最終ジャッジ日時 2023-10-12 16:14:47
合計ジャッジ時間 10,301 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,744 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,356 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 7 ms
8,232 KB
testcase_16 AC 10 ms
14,640 KB
testcase_17 AC 27 ms
20,892 KB
testcase_18 AC 89 ms
27,320 KB
testcase_19 AC 95 ms
29,100 KB
testcase_20 AC 81 ms
33,008 KB
testcase_21 AC 119 ms
33,244 KB
testcase_22 AC 134 ms
32,964 KB
testcase_23 AC 1,823 ms
33,756 KB
testcase_24 AC 1,117 ms
33,372 KB
testcase_25 AC 1,076 ms
34,356 KB
testcase_26 TLE -
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 "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

template<class T> void chmax(T& a,const T& b){a=max(a,b);}
template<class T> void chmin(T& a,const T& b){a=min(a,b);}

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60;
const int MAX_N = 2003;

ll dp[MAX_N][MAX_N];
vector<int> graph[MAX_N];
int part[MAX_N];

int main(){
  int N,K;
  cin >> N >> K;
  rep(i,N-1){
    int a,b; cin >> a >> b;
    graph[a].pb(b); graph[b].pb(a);
  }
  rep(i,N) rep(j,K+1) dp[i][j] = 0LL;
  rep(i,N) dp[i][0] = 1LL;
  fill(part,part+N,1);
  function<void(int,int)> dfs = [&](int u,int p){
    for(auto v:graph[u]){
      if(v==p) continue;
      dfs(v,u);
      part[u] += part[v];
      vector<ll> table(part[u]+1,0);
      rep(j,part[u]+1){
        rep(l,part[v]+1){
          if(j-l>=0) (table[j] += dp[v][l] * dp[u][j-l]) %= lmod;
        }
      }
      rep(j,part[u]+1) dp[u][j] = table[j];
    }
    dp[u][part[u]] = 1LL;
    return ;
  };
  dfs(0,-1);
  cout << dp[0][K] << endl;
  // rep(i,N){ rep(j,K+1) cout << dp[i][j] << " "; cout << endl;}
  return 0;
}
0