题目描述
求无向图的所有导出子图的最大独立集大小的和.
导出子图:若图 是图 的导出子图,则
-
图 的点集是图 的点集的子集;
-
中存在边 ,当且仅当点 , 在 中,且 中存在边 .
独立集:图中两两互不相邻的顶点构成的集合.
最大独立集:点数最大的独立集.
数据范围
对 的数据, , .
题解
考虑新加入一个节点对原来的图的影响
所以设 表示选择了 状态的点的最大独立集点数
假设新加入一个节点 ,那对于原来的图的状态 ,可以列出 式子:
其中 为与 相连的点的状态
代码
#include <bits/stdc++.h>
using namespace std;
int n,m,a[27],f[1<<26],ans;
int main(){
scanf("%d%d",&n,&m);
for (int u,v,i=0;i<m;i++)
scanf("%d%d",&u,&v),
a[v]|=(1<<u),a[u]|=(1<<v);
for (int s=1,i=0;i<n;i++,s<<=1)
for (int j=0;j<s;j++)
f[j|s]=max(f[j],f[j&(~a[i])]+1);
for (int i=(1<<n)-1;~i;i--) ans+=f[i];
return printf("%d\n",ans),0;
}