結果

問題 No.196 典型DP (1)
ユーザー motimoti
提出日時 2015-07-15 19:27:15
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,110 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 80,044 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-22 16:34:51
合計ジャッジ時間 2,373 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 8 ms
4,380 KB
testcase_27 AC 9 ms
4,376 KB
testcase_28 AC 8 ms
4,380 KB
testcase_29 AC 8 ms
4,376 KB
testcase_30 AC 8 ms
4,500 KB
testcase_31 AC 12 ms
4,376 KB
testcase_32 AC 12 ms
4,376 KB
testcase_33 AC 12 ms
4,376 KB
testcase_34 AC 12 ms
4,380 KB
testcase_35 AC 12 ms
4,376 KB
testcase_36 AC 12 ms
4,380 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 12 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

using VLL = vector<int>;

int constexpr MOD = 1e9+7;
int constexpr Max = 2010;

int N, K;
VLL g[Max];

auto rec(int curr, int parent)
  -> VLL  // 着目している根付き木について、黒く塗られている数->そのパターン数
{
  VLL ret(1, 1);
  for(auto ch: g[curr]) {
    if(ch == parent) { continue; }
    auto subTree = rec(ch, curr);
    auto currK = ret.size() - 1; // 自分を除く
    auto newK = subTree.size() - 1; // 自分を除く
    VLL nret(currK + newK + 1);
    rep(iteCurrK, currK + 1) rep(iteNewK, newK + 1) {
      (nret[iteCurrK + iteNewK] += ret[iteCurrK] * subTree[iteNewK]) %= MOD;
    }
    ret = nret;
  }
  ret.push_back(1);
  return std::move(ret);
}

int main() {

  cin >> N >> K;
  rep(i, N-1) {
    int a, b; cin >> a >> b;
    g[a].push_back(b), g[b].push_back(a);
  }

  cout << rec(0, -1)[K] << endl;

  return 0;
}
0