結果
| 問題 |
No.196 典型DP (1)
|
| コンテスト | |
| ユーザー |
airis
|
| 提出日時 | 2015-05-10 15:14:46 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,431 bytes |
| コンパイル時間 | 696 ms |
| コンパイル使用メモリ | 78,852 KB |
| 実行使用メモリ | 19,584 KB |
| 最終ジャッジ日時 | 2024-07-05 21:24:52 |
| 合計ジャッジ時間 | 2,889 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 WA * 18 |
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <numeric>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
int N, K;
vector<int> G[2005];
vector<int> dp[2005]; //dp[i][j] iを根とした部分グラフにj個塗る場合は何通りあるか
int dfs(int cur, int prev) {
int sum = 1; //curを根とした部分グラフに存在する頂点の数
dp[cur][0] = 1;
rep(i, G[cur].size()) {
int adj = G[cur][i]; // 隣接ノード
if (adj == prev) continue;
int num = dfs(adj, cur);
vector<int> tmp(2005, 0);
for (int j = 0; j <= sum; j++) {
for (int k = 0; k <= num; k++) {
tmp[j + k] += dp[cur][j] * dp[adj][k];
}
}
dp[cur] = tmp;
sum += num;
}
dp[cur][sum] = 1;
return sum;
}
int a, b;
int main() {
rep(i, 2005) dp[i].resize(2005, 0);
cin >> N >> K;
while (cin >> a >> b) {
G[a].push_back(b);
G[b].push_back(a);
}
dfs(0, -1);
#if 0
rep(i, 5) rep(j, 5) {
printf("%d%c", dp[i][j], j == 5-1 ? '\n' : ' ');
}
#endif
cout << dp[0][K] << endl;
return 0;
}
airis