結果

問題 No.196 典型DP (1)
ユーザー koba-e964koba-e964
提出日時 2015-06-05 17:52:22
言語 C++11
(gcc 11.4.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,700 bytes
コンパイル時間 2,566 ms
コンパイル使用メモリ 73,188 KB
実行使用メモリ 804,700 KB
最終ジャッジ日時 2023-09-20 19:18:42
合計ジャッジ時間 5,146 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int rec_p(int, int)’:
main.cpp:41:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
const double EPS=1e-9;
typedef vector<int> VI;
const int N = 2010;

const int DEBUG = 0;
VI graph[N];
int parent[N];
int desc[N];

ll dp[N][N];
const ll mod = 1e9+7;
int rec_p(int n, int p) {
  parent[n] = -2;
  int s = 0;
  REP(i, 0, graph[n].size()) {
    int v = graph[n][i];
    if (parent[v] != -2) {
      rec_p(v, n);
      s += desc[v] + 1;
    }
  }
  parent[n] = p;
  desc[n] = s;
}
// [0,d]
void poly_mul(ll aa[N], const ll bb[N], int da, int db) {
  ll cc[N] = {0};
  REP(i, 0, da + 1) {
    REP(j, 0, db + 1) {
      cc[i + j] += aa[i] * bb[j];
      cc[i + j] %= mod;
    }
  }
  REP(i, 0, da + db + 1) {
    if (DEBUG) {
      cout << cc[i] << "x^" << i << "+";
    }

    aa[i] = cc[i];
  }
  if (DEBUG) {
    cout << endl;
  }
}

void rec(int v) {
  dp[v][0] = 1;
  int d = 0;
  REP(i, 0, graph[v].size()) {
    int u = graph[v][i];
    if (u == parent[v]) {
      continue;
    }
    rec(u);
    poly_mul(dp[v], dp[u], d, desc[u] + 1);
    d += desc[u] + 1;
  }
  dp[v][desc[v] + 1] = 1;
}

int main(void){
  int n, k;
  cin >> n >> k;
  REP (i, 0, n - 1) {
    int a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  rec_p(0, -1);
  if (DEBUG) {
    REP(i, 0, n) {
      cout << "p[" << i << "]=" << parent[i] << endl;
    }
  }
  REP(i,0,N) {
    fill_n(dp[i], N, 0);
    dp[i][0] = 1;
  }
  rec(0);
  cout << dp[0][k] << endl;
}
0