independent set 1
independent set 1
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 102400K,其他语言204800K
64bit IO Format: %lld
题目描述
An induced subgraph G'(V', E') of a graph G(V, E) is a graph that satisfies:
* V′⊆V
* edge (a,b)∈E′ if and only if a∈V′,b∈V′, and edge (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 2^n possible induced subgraphs of the given graph. Please calculate the sum of the 2^n such cardinalities.
输入描述:
The first line contains two integers n and m (2≤n≤26,0≤m≤n×(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,yi (0≤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.
输入
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.
链接:https://ac.nowcoder.com/acm/contest/885/E
来源:牛客网
题意:求一个图的2^n种子图的最大点独立集。
思路:
•我们可以用一个 n-bit 2 进制整数来表示一个点集,第 i 个 bit 是 1 就代表点集包含第 i 个 点,若是 0 则不包含
• 每个点相邻的点也可以用一个 n-bit 2 进制整数表示,计做 ci,若第 i 个点和第 j 个点相邻, ci 的第 j 个 bit 是 1,否则是 0
• 记 x 的最低位且是 1 的 bit 的位置是 lbx
• 令 dp[x] 代表点集 x 的最大独立集 size,那么我们能够根据点 lbx 是否属于最大独立集来列 出以下关系式:
dp[x] = max(dp[x - (1<<lbx)], dp[x & (~clb_x)] + 1) (使用 c 语言运算符)
•高效位运算参考博客:https://blog.csdn.net/yuer158462008/article/details/46383635
#include<bits/stdc++.h>
using namespace std;
char dp[<<];
int Map[]={};
int max(char a,int b)
{
if(a>b)return a;
return b;
}
int main()
{
int n,m;
scanf("%d %d",&n,&m); while(m--)
{
int u,v;
scanf("%d %d",&u,&v);
Map[u]|=(<<v);
Map[v]|=(<<u);
}
for(int i=;i<n;i++)Map[i]|=<<i; int upper=<<n;
long long ans=;
for(int i=;i<upper;i++)
{
int lbx=__builtin_ctz(i);
dp[i] = max(dp[i - (<<lbx)] , dp[i & (~Map[lbx])] + );
ans+=dp[i];
}
printf("%lld\n",ans);
return ;
}
independent set 1的更多相关文章
- 写一个程序可以对两个字符串进行测试,得知第一个字符串是否包含在第二个字符串中。如字符串”PEN”包含在字符串“INDEPENDENT”中。
package lovo.test; import java.util.Scanner; public class Java { @param args public static void main ...
- Deep Learning 13_深度学习UFLDL教程:Independent Component Analysis_Exercise(斯坦福大学深度学习教程)
前言 理论知识:UFLDL教程.Deep learning:三十三(ICA模型).Deep learning:三十九(ICA模型练习) 实验环境:win7, matlab2015b,16G内存,2T机 ...
- [ZZ] KlayGE 游戏引擎 之 Order Independent Transparency(OIT)
转载请注明出处为KlayGE游戏引擎,本文的永久链接为http://www.klayge.org/?p=2233 http://dogasshole.iteye.com/blog/1429665 ht ...
- Andrew Ng机器学习公开课笔记–Independent Components Analysis
网易公开课,第15课 notes,11 参考, PCA本质是旋转找到新的基(basis),即坐标轴,并且新的基的维数大大降低 ICA也是找到新的基,但是目的是完全不一样的,而且ICA是不会降维的 对于 ...
- Questions that are independent of programming language. These questions are typically more abstract than other categories.
Questions that are independent of programming language. These questions are typically more abstract ...
- Interview-Largest independent set in binary tree.
BT(binary tree), want to find the LIS(largest independent set) of the BT. LIS: if the current node i ...
- 【转】NDK编译可执行文件在Android L中运行显示error: only position independent executables (PIE) are supported.失败问题解决办法。
原文网址:http://blog.csdn.net/hxdanya/article/details/39371759 由于使用了NDK编译的可执行文件在应用中调用,在4.4及之前的版本上一直没出问题. ...
- 基于Hama并联平台Finding a Maximal Independent Set 设计与实现算法
笔者:白松 NPU学生. 转载请注明出处:http://blog.csdn.net/xin_jmail/article/details/32101483. 本文參加了2014年CSDN博文大赛,假设您 ...
- More than one file was found with OS independent path 錯誤
More than one file was found with OS independent path 'lib/armeabi/libmrpoid.so',. 翻譯過來就是:在操作系統的獨立目錄 ...
- More than one file was found with OS independent path 'META-INF/LICENSE' | Error:Could not read \build\intermediates\typedefs.txt (系统找不到指定的文件。)
FAQ1: Error:Could not read E:\new\PlatformLibrary\CommonLibrary\build\intermediates\typedefs.txt: E: ...
随机推荐
- POJ 1584 /// 判断圆(点)在多边形内 判断凸包
题目大意: 给定n,n边形 给定圆钉的 半径r 和圆心(x,y) 接下来n行是n边形的n个顶点(顺时针或逆时针给出) 判断n边形是否为凸包 若不是输出 HOLE IS ILL-FORMED 判断圆心和 ...
- CodeForces 258D Little Elephant and Broken Sorting(期望)
CF258D Little Elephant and Broken Sorting 题意 题意翻译 有一个\(1\sim n\)的排列,会进行\(m\)次操作,操作为交换\(a,b\).每次操作都有\ ...
- Java系列笔记(4) - JVM监控与调优【转】
Java系列笔记(4) - JVM监控与调优[转] 目录 参数设置收集器搭配启动内存分配监控工具和方法调优方法调优实例 光说不练假把式,学习Java GC机制的目的是为了实用,也就是为了在 ...
- VS2012 TFS 解决计算机改名无法连接TFS的问题
闲着没事改了下计算机名字,结果造成TFS无法连接. 报错讯息如下: ---------------------------Microsoft Visual Studio-------------- ...
- Cooki and Session
目录 Cookie Cookie的由来 什么是Cookie Cookie的原理 查看Cookie Django中操作Cookie 获取Cookie 设置Cookie 删除Cookie Session ...
- org.apache.commons工具类方法解释 转
在Java中,工具类定义了一组公共方法,这篇文章将介绍Java中使用最频繁及最通用的Java工具类.以下工具类.方法按使用流行度排名,参考数据来源于Github上随机选取的5万个开源项目源码. 一. ...
- C#生成指定范围内的不重复随机数
C#生成指定范围内的不重复随机数 // Number随机数个数 // minNum随机数下限 // maxNum随机数上限 public int[] GetRandomArray(int Number ...
- js格式化数字为金额
/** * * @param num * @param precision * @param separator * @returns {*} *=========================== ...
- elasticsearch 中文API 记数(八)
计数API 计数API允许开发者简单的执行一个查询,返回和查询条件相匹配的文档的总数.它可以跨多个索引以及跨多个类型执行. import static org.elasticsearch.index. ...
- STL容器-deque-双端队列
注明:全部来自转载,供自己学习与复习使用 deque双向开口可进可出的容器 我们知道连续内存的容器不能随意扩充,因为这样容易扩充别人那去 deque却可以,它创造了内存连续的假象. 其实deque由一 ...