結果

問題 No.196 典型DP (1)
ユーザー ei1333333ei1333333
提出日時 2015-09-09 15:26:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 822 bytes
コンパイル時間 1,243 ms
コンパイル使用メモリ 146,512 KB
実行使用メモリ 18,880 KB
最終ジャッジ日時 2023-09-26 10:15:07
合計ジャッジ時間 3,407 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 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 12 ms
18,880 KB
testcase_27 AC 12 ms
18,856 KB
testcase_28 AC 12 ms
18,824 KB
testcase_29 AC 12 ms
18,800 KB
testcase_30 AC 12 ms
18,852 KB
testcase_31 AC 10 ms
17,560 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 11 ms
17,524 KB
testcase_36 AC 10 ms
17,684 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 11 ms
17,468 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

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] += dp[idx][j] * dp[graph[idx][i]][k];
      }
    }
    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