博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
P59330-[清华集训2012]串珠子【状压dp】
阅读量:2022 次
发布时间:2019-04-28

本文共 888 字,大约阅读时间需要 2 分钟。

正题

题目链接:


题目大意

n n n个点的一张无向图,求所有联通子图的权值乘积和


解题思路

因为 n n n很小,考虑状压

f i f_i fi表示点集为 i i i时的方案数,我们发现正着做十分麻烦,考虑容斥。
首先定义 m u l i mul_i muli表示点集 i i i的所有子图的方案数,那么显然有 m u l i = ∏ x , y ∈ i , x < y ( a x , y + 1 ) mul_i=\prod^{x,y\in i,x<y}(a_{x,y}+1) muli=x,yi,x<y(ax,y+1)
枚举一个集合 s s s有转移方程,选出一个点 p p p一定在联通图内,这里状压为只有一个点 p p p的集合 f s = m u l s − ∑ i ∈ ( s − p ) f i + p ∗ m u l s − p − i f_s=mul_s-\sum_{i\in (s-p)}f_{i+p}*mul_{s-p-i} fs=mulsi(sp)fi+pmulspi
时间复杂度 O ( 3 n ) O(3^n) O(3n)


c o d e code code

#include
#include
#include
#define ll long longusing namespace std;const ll N=17,XJQ=1e9+7;ll n,mul[1<
<
>i)&1))continue; mul[s]=mul[s^(1<
>i)&1)&&((s>>j)&1)) mul[s]=mul[s]*(a[i][j]+1)%XJQ; break; } } mul[0]=0; for(ll s=1;s
=0;j=(j==0?-1:((j-1)&i))) f[s]=(f[s]-f[j+p]*mul[i-j]%XJQ+XJQ)%XJQ; } printf("%lld",f[MS-1]);}

转载地址:http://ucwaf.baihongyu.com/

你可能感兴趣的文章
SolrJ
查看>>
展示树菜单(zTree)
查看>>
spring安全框架:spring-security
查看>>
quartz实现定时任务
查看>>
angularJS基础使用(一)
查看>>
javamail
查看>>
Makefile函数
查看>>
Makefile自动产生依赖
查看>>
互斥:软件算法
查看>>
GCC内联汇编
查看>>
重载new和delete
查看>>
句柄类
查看>>
GPIO
查看>>
正则表达式
查看>>
makefile变量
查看>>
makefile规则
查看>>
makefile函数
查看>>
makefile简介
查看>>
makefile指令
查看>>
基本shell命令
查看>>