题干:

链接:https://ac.nowcoder.com/acm/contest/885/E
来源:牛客网

Note: For C++ languages, the memory limit is 100 MB. For other languages, the memory limit is 200 MB.

In graph theory, an independent set is a set of nonadjacent vertices in a graph. Moreover, an independent set is maximum if it has the maximum cardinality (in this case, the number of vertices) across all independent sets in a graph.

An induced subgraph G'(V', E') of a graph G(V, E) is a graph that satisfies:

* V′⊆VV' \subseteq VV′⊆V

* edge (a,b)∈E′(a,b) \in E'(a,b)∈E′ if and only if a∈V′,b∈V′a \in V', b \in V'a∈V′,b∈V′, and edge (a,b)∈E(a, b) \in E(a,b)∈E;

Now, given an undirected unweighted graph consisting of n vertices and m edges. This problem is about the cardinality of the maximum independent set of each of the 2n2^n2n possible induced subgraphs of the given graph. Please calculate the sum of the 2n2^n2n such cardinalities.

输入描述:

The first line contains two integers n and m (2≤n≤26,0≤m≤n×(n−1)22 \le n \le 26, 0 \le m \le \frac{n \times (n-1)}{2}2≤n≤26,0≤m≤2n×(n−1)​) --- the number of vertices and the number of edges, respectively. Next m lines describe edges: the i-th line contains two integers xi,yix_i, y_ixi​,yi​ (0≤xi<yi<n0 \le x_i < y_i < n0≤xi​<yi​<n) --- the indices (numbered from 0 to n - 1) of vertices connected by the i-th edge.The graph does not have any self-loops or multiple edges.

输出描述:

Print one line, containing one integer represents the answer.

示例1

输入

复制

3 2
0 1
0 2

输出

复制

9

说明

The cardinalities of the maximum independent set of every subset of vertices are: {}: 0, {0}: 1, {1}: 1, {2}: 1, {0, 1}: 1, {0, 2}: 1, {1, 2}: 2, {0, 1, 2}: 2. So the sum of them are 9.

示例2

输入

复制

7 5
0 5
3 4
1 2
2 5
0 2

输出

复制

328

题目大意:

给一个n个点m条边的无向图,求所有子图(包括本身)的最大独立集元素个数之和。(2<=n<=26)

解题报告:

直接状压dp,求出对于每一个子图的最大独立集的元素之和就可以了。

转移方程:dp[sta]=max(dp[最大独立集不包含这个点],dp[包含这个点])。

然后卡空间,所以要char类型。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 1<<26;
int b[MAX];
char p[MAX],dp[MAX];
int n,m;
int main()
{cin>>n>>m;int ans = 0;for(int u,v,i = 1; i<=m; i++) {scanf("%d%d",&u,&v);b[u] |= 1<<v;b[v] |= 1<<u;                }dp[0] = 0;for(int sta = 1; sta < (1<<n); sta++) {int x = __builtin_ffs(sta);x--;dp[sta] = max((int)dp[sta-(1<<x)],dp[sta - (1<<x) - (sta & b[x])] + 1);ans += dp[sta];}printf("%d\n",ans);return 0 ;
}

【2019牛客暑期多校训练营(第五场)- E】independent set 1(最大独立集,状压dp)相关推荐

  1. 【2019牛客暑期多校训练营(第二场) - H】Second Large Rectangle(单调栈,全1子矩阵变形)

    题干: 链接:https://ac.nowcoder.com/acm/contest/882/H 来源:牛客网 题目描述 Given a N×MN \times MN×M binary matrix. ...

  2. 2019牛客暑期多校训练营(第一场)E-ABBA(dp)

    链接:https://ac.nowcoder.com/acm/contest/881/E 来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...

  3. 2019牛客暑期多校训练营(第一场)

    传送门 参考资料: [1]:官方题解(提取码:t050 ) [2]:标程(提取码:rvxr ) [3]:牛客题解汇总 A.Equivalent Prefixes(单调栈) •题意 定义两个数组 u,v ...

  4. 2019牛客暑期多校训练营(第一场) A Equivalent Prefixes ( st 表 + 二分+分治)

    链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/ ...

  5. 【2019牛客暑期多校训练营(第二场)- E】MAZE(线段树优化dp,dp转矩阵乘法,线段树维护矩阵乘法)

    题干: 链接:https://ac.nowcoder.com/acm/contest/882/E?&headNav=acm 来源:牛客网 Given a maze with N rows an ...

  6. 【2019牛客暑期多校训练营(第二场)- F】Partition problem(dfs,均摊时间优化)

    题干: 链接:https://ac.nowcoder.com/acm/contest/882/F 来源:牛客网 Given 2N people, you need to assign each of ...

  7. 【2019牛客暑期多校训练营(第二场) - D】Kth Minimum Clique(bfs,tricks)

    题干: 链接:https://ac.nowcoder.com/acm/contest/882/D 来源:牛客网 Given a vertex-weighted graph with N vertice ...

  8. 【2019牛客暑期多校训练营(第一场) - A】Equivalent Prefixes(单调栈,tricks)

    题干: 链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Two arrays u and v each with m distinct elem ...

  9. 【2019牛客暑期多校训练营(第一场) - H】XOR(线性基,期望的线性性)

    题干: 链接:https://ac.nowcoder.com/acm/contest/881/H 来源:牛客网 Bobo has a set A of n integers a1,a2,-,ana1, ...

  10. 2019牛客暑期多校训练营(第九场)H Cutting Bamboos(主席树+二分)

    链接:https://ac.nowcoder.com/acm/contest/889/H 来源:牛客网 题目描述 There are n bamboos arranged in a line. The ...

最新文章

  1. hbase 修改表名_HBase学习——2.HBase原理
  2. GIT使用总结(二)
  3. centos7 mysql读写监控_Centos7 Zabbix监控mysql
  4. 海致java面试_海致面试
  5. 请检查virtualboxapi是否正确安装_MBR膜组件安装施工方案指南
  6. react与微信小程序
  7. 阿里:车联网将成新网络入口
  8. ExcelHelper代码
  9. 牛客网 牛客练习赛7 A.骰子的游戏
  10. 吴恩达机器学习视频学习笔记(4)
  11. PostgreSQL客户端验证
  12. 制作win7 u盘启动盘
  13. 想了解阀门的请进!!!!
  14. 软件测试中性能瓶颈是什么,性能测试常见瓶颈分析及调优方法
  15. 2022年驾驶员考试装载车司机考试模拟试题卷及答案
  16. 怎样设置用键盘开机?
  17. liferay portlet二次开发多个ajax数据传递
  18. 联想服务器重装系统只有光标,联想bios重装系统图文教程
  19. 星巴克公司员工股权激励机制
  20. 7-40 奥运排行榜

热门文章

  1. Js——elementFromPoint方法
  2. 【知识导图】数据结构与算法
  3. [剑指offer]面试题第[59-2]题[JAVA][队列的最大值][暴力][双端队列]
  4. [剑指offer][JAVA]面试题第[34]题[二叉树中和为某一值的路径][回溯]
  5. [Leedcode][JAVA][第5题][最长回文子串][数组][动态规划]
  6. [Leedcode][JAVA][第50题][Pow(x, n)][快速幂][分治][转换类型]
  7. python装饰器调用顺序_聊一聊Python装饰器的代码执行顺序
  8. python抢货程序_Python自动化xpath实现自动抢票抢货代码示例
  9. micropython oled中文_micropython中怎么将gb2312编码的字节流变成中文
  10. esxi usb插口_酷暑大作战 | USB-C风扇新体验