# HDU 5713 & 2016"百度之星" 复赛（Astar Round3）1002 k个联通块

dp[s][k]=sigma(dp[s1][k1]+f[s$dp[s][k] = sigma(dp[s1][k-1] + f[s$^s1])$s1])$

h[s]=sigma(f[s1]g[s$h[s] = sigma(f[s1] * g[s$^s1])$s1])$

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<ctime>
#define eps 1e-6
#define LL long long
#define pii pair<int, int>
using namespace std;
const int mod = 1e9+9;
const int maxn = 15;

int n, m, q, num[1<<maxn], G[maxn][maxn];
LL f[1<<maxn], h[1<<maxn], p[maxn*maxn], dp[1<<maxn][maxn];
void init() {
memset(G, 0, sizeof(G));
memset(num, 0, sizeof(num));
memset(f, 0, sizeof(f));
memset(h, 0, sizeof(h));
}
inline int lowbit(int x) {
return x&-x;
}
int cal_edge(int e, int s) {
int ans = 0;
for (int i = 0; i < n; i++)
if ((1<<i) == e) {
e = i;
break;
}
for (int i = 0; i < n; i++)
if ((1<<i)&s)
ans += G[i][e];
return ans;
}

int main()
{
freopen("input.txt", "r", stdin);
int T;
cin >> T;
int kase = 0;
p[0] = 1;
for (int i = 1; i <= 200; i++) {
p[i] = p[i-1] << 1;
p[i] %= mod;
}
while (T--) {
scanf("%d%d%d", &n, &m, &q);
init();
int maxs = 1 << n;
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d%d", &u, &v);
u--;
v--;
G[u][v] = G[v][u] = 1;
}
num[0] = 0;
for (int i = 1; i < maxs; i++) {
int t = lowbit(i);
num[i] = num[i^t] + cal_edge(t, i);
}
for (int i = 0; i < n; i++)
f[1<<i] = p[num[1<<i]];
for (int i = 1; i < maxs; i++) {
int t = lowbit(i);
for (int j = i^t; j; j=(j-1)&(i^t)) {
h[i] += f[i^j] * p[num[j]];
h[i] %= mod;
}
f[i] = p[num[i]] - h[i];
f[i] %= mod;
}
for (int i = 1; i < maxs; i++)
dp[i][1] = f[i];
for (int i = 1; i < maxs; i++) {
for (int k = 2; k <= q; k++) {
dp[i][k] = 0;
int t = lowbit(i);
for (int j = i^t; j; j=(j-1)&(i^t)) {
dp[i][k] += dp[j][k-1] * f[i^j];
dp[i][k] %= mod;
}
}
}
if (dp[maxs-1][q] < 0)
dp[maxs-1][q] += mod;
printf("Case #%d:\n%I64d\n", ++kase, dp[maxs-1][q]);
}
return 0;
}



• 本文已收录于以下专栏：

## "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场（重现）解题思路

"巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场（重现）解题思路

## 2016"百度之星" - 复赛（Astar Round3）1003 1004

1003 拍照Problem Description小明在旅游的路上看到了一条美丽的河，河上有许多船只， 有的船只向左航行，有的船只向右航行。 小明希望拍下这一美丽的风景，并且把尽可能多的船只都完整地...

## 2016"百度之星" - 初赛（Astar Round2B）1003 瞬间移动(HDU5698)(逆元+快速幂）

2016”百度之星” - 初赛（Astar Round2B）1003 瞬间移动(HDU5698)(逆元+快速幂）Time Limit: 4000/2000 MS (Java/Others) ...

## 2016"百度之星" - 资格赛(Astar Round1)-(模拟+线段树+乘法逆元)

Problem A    Accepts: 1351    Submissions: 9951  Time Limit: 2000/1000 MS (Java/Others)    ...

举报原因： 您举报文章：HDU 5713 & 2016"百度之星" 复赛（Astar Round3）1002 k个联通块 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)