結果

問題 No.196 典型DP (1)
ユーザー ei1333333ei1333333
提出日時 2015-09-09 15:28:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 869 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 146,500 KB
実行使用メモリ 19,116 KB
最終ジャッジ日時 2023-09-26 10:15:20
合計ジャッジ時間 4,043 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 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 18 ms
19,116 KB
testcase_27 AC 18 ms
18,952 KB
testcase_28 AC 18 ms
18,772 KB
testcase_29 AC 18 ms
18,808 KB
testcase_30 AC 19 ms
18,892 KB
testcase_31 AC 13 ms
17,436 KB
testcase_32 AC 14 ms
17,500 KB
testcase_33 AC 14 ms
17,500 KB
testcase_34 AC 13 ms
17,500 KB
testcase_35 AC 14 ms
17,496 KB
testcase_36 AC 13 ms
17,440 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 13 ms
17,644 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int N, K;
vector< int > graph[2000];

int dp[2000][2001];
int num[2000];
int rec(int idx, int prev)
{
  for(int i = 0; i < graph[idx].size(); i++) {
    if(graph[idx][i] != prev) rec(graph[idx][i], idx);
  }
  dp[idx][0] = 1;
  num[idx] = 1;
  for(int i = 0; i < graph[idx].size(); i++) {
    if(graph[idx][i] == prev) continue;
    for(int j = num[idx]; j >= 0; j--) {
      for(int k = num[graph[idx][i]]; k >= 1; k--) {
        (dp[idx][j + k] += (long long)dp[idx][j] * dp[graph[idx][i]][k]) %= mod;
      }
    }
    num[idx] += num[graph[idx][i]];
  }
  dp[idx][num[idx]] = 1;
  return(dp[idx][K]);
}

int main()
{
  cin >> N >> K;
  for(int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  cout << rec(0, -1) << endl;
}
0