結果

問題 No.196 典型DP (1)
ユーザー airisairis
提出日時 2015-05-10 15:14:46
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,431 bytes
コンパイル時間 813 ms
コンパイル使用メモリ 78,388 KB
実行使用メモリ 19,576 KB
最終ジャッジ日時 2023-09-19 09:42:04
合計ジャッジ時間 3,795 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
19,252 KB
testcase_01 AC 15 ms
19,136 KB
testcase_02 AC 15 ms
19,072 KB
testcase_03 AC 14 ms
19,188 KB
testcase_04 AC 15 ms
19,064 KB
testcase_05 AC 14 ms
19,068 KB
testcase_06 AC 14 ms
19,112 KB
testcase_07 AC 14 ms
19,284 KB
testcase_08 AC 15 ms
19,380 KB
testcase_09 AC 14 ms
19,164 KB
testcase_10 AC 15 ms
19,324 KB
testcase_11 AC 15 ms
19,064 KB
testcase_12 WA -
testcase_13 AC 15 ms
19,188 KB
testcase_14 AC 14 ms
19,424 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 24 ms
19,452 KB
testcase_27 AC 23 ms
19,340 KB
testcase_28 AC 23 ms
19,392 KB
testcase_29 AC 23 ms
19,412 KB
testcase_30 AC 24 ms
19,448 KB
testcase_31 AC 23 ms
19,188 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 22 ms
19,272 KB
testcase_36 AC 21 ms
19,252 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 22 ms
19,312 KB
testcase_41 AC 15 ms
19,064 KB
testcase_42 AC 15 ms
19,284 KB
testcase_43 AC 15 ms
19,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}


0