independent set 1

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 102400K,其他语言204800K
64bit IO Format: %lld

题目描述

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′⊆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.

输入描述:

  1. The first line contains two integers n and m (2n26,0mn×(n1)​) --- the number of vertices and the number of edges, respectively. Next m lines describe edges: the i-th line contains two integers xi,yi (0xi<yi<n) --- the indices (numbered from 0 to n - 1) of vertices connected by the i-th edge.
  2.  
  3. The graph does not have any self-loops or multiple edges.

输出描述:

  1. Print one line, containing one integer represents the answer.

输入

  1. 3 2
  2. 0 1
  3. 0 2

输出

  1. 9

说明

  1. 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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. char dp[<<];
  4. int Map[]={};
  5. int max(char a,int b)
  6. {
  7. if(a>b)return a;
  8. return b;
  9. }
  10. int main()
  11. {
  12. int n,m;
  13. scanf("%d %d",&n,&m);
  14.  
  15. while(m--)
  16. {
  17. int u,v;
  18. scanf("%d %d",&u,&v);
  19. Map[u]|=(<<v);
  20. Map[v]|=(<<u);
  21. }
  22. for(int i=;i<n;i++)Map[i]|=<<i;
  23.  
  24. int upper=<<n;
  25. long long ans=;
  26. for(int i=;i<upper;i++)
  27. {
  28. int lbx=__builtin_ctz(i);
  29. dp[i] = max(dp[i - (<<lbx)] , dp[i & (~Map[lbx])] + );
  30. ans+=dp[i];
  31. }
  32. printf("%lld\n",ans);
  33. return ;
  34. }

independent set 1的更多相关文章

  1. 写一个程序可以对两个字符串进行测试,得知第一个字符串是否包含在第二个字符串中。如字符串”PEN”包含在字符串“INDEPENDENT”中。

    package lovo.test; import java.util.Scanner; public class Java { @param args public static void main ...

  2. Deep Learning 13_深度学习UFLDL教程:Independent Component Analysis_Exercise(斯坦福大学深度学习教程)

    前言 理论知识:UFLDL教程.Deep learning:三十三(ICA模型).Deep learning:三十九(ICA模型练习) 实验环境:win7, matlab2015b,16G内存,2T机 ...

  3. [ZZ] KlayGE 游戏引擎 之 Order Independent Transparency(OIT)

    转载请注明出处为KlayGE游戏引擎,本文的永久链接为http://www.klayge.org/?p=2233 http://dogasshole.iteye.com/blog/1429665 ht ...

  4. Andrew Ng机器学习公开课笔记–Independent Components Analysis

    网易公开课,第15课 notes,11 参考, PCA本质是旋转找到新的基(basis),即坐标轴,并且新的基的维数大大降低 ICA也是找到新的基,但是目的是完全不一样的,而且ICA是不会降维的 对于 ...

  5. 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 ...

  6. 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 ...

  7. 【转】NDK编译可执行文件在Android L中运行显示error: only position independent executables (PIE) are supported.失败问题解决办法。

    原文网址:http://blog.csdn.net/hxdanya/article/details/39371759 由于使用了NDK编译的可执行文件在应用中调用,在4.4及之前的版本上一直没出问题. ...

  8. 基于Hama并联平台Finding a Maximal Independent Set 设计与实现算法

    笔者:白松 NPU学生. 转载请注明出处:http://blog.csdn.net/xin_jmail/article/details/32101483. 本文參加了2014年CSDN博文大赛,假设您 ...

  9. More than one file was found with OS independent path 錯誤

    More than one file was found with OS independent path 'lib/armeabi/libmrpoid.so',. 翻譯過來就是:在操作系統的獨立目錄 ...

  10. 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: ...

随机推荐

  1. Django之跨表查询——正反向查询(ForeignKey)

    1.正向查询和反向查询: 外键的查询操作: 正向查询: # 正向查询 # 基于对象,跨表查询 book_obj = models.Book.objects.all().first() ret = bo ...

  2. pip的使用方法简介

    pip是Python包管理工具,它提供了对Python包的查找.下载.安装.卸载的功能 目前如果你在 python.org 下载最新版本的安装包,则是已经自带了该工具. 以下是pip常用命令 显示版本 ...

  3. 面试系列15 如何保证Redis的高并发和高可用

    就是如果你用redis缓存技术的话,肯定要考虑如何用redis来加多台机器,保证redis是高并发的,还有就是如何让Redis保证自己不是挂掉以后就直接死掉了,redis高可用 我这里会选用我之前讲解 ...

  4. Python全栈开发:冒泡排序

    #!/usr/bin/env python # -*- coding;utf-8 -*- """ 第一次对比:找到最大值,放到最后 对比是两两对比,对比的两个数组合共有l ...

  5. CentOS7服务器中apache、php7以及mysql5.7的安装配置代码

    CentOS7服务器中apache.php7以及mysql5.7的配置代码如下所示: yum upgradeyum install net-tools 安装apache (http://m.86822 ...

  6. LUGOU P1092 虫食算

    传送门 解题思路 刚开始按yzy神犇给的方法写,就是每次要把能算出来的都算出来,结果因为太菜写挂了..后来直接爆搜水过.. #include<iostream> #include<c ...

  7. 洛谷P4027 [NOI2007]货币兑换

    P4027 [NOI2007]货币兑换 算法:dp+斜率优化 题面十分冗长,题意大概是有一种金券每天价值会有变化,你可以在某些时间点买入或卖出所有的金券,问最大收益 根据题意,很容易列出朴素的状态转移 ...

  8. php链表笔记:链表的检测

    <?php /** * Created by PhpStorm. * User: huizhou * Date: 2018/12/2 * Time: 11:48 */ /** * 链表的检测 * ...

  9. 为WCF增加UDP绑定(实践篇)

    这两天忙着系统其它功能的开发,没顾上写日志.本篇所述皆围绕为WCF增加UDP绑定(储备篇)中讲到的微软示例,该示例我已上传到网盘. 上篇说道,绑定是由若干绑定元素有序组成,为WCF增加UDP绑定其实就 ...

  10. Chrome快捷键, Mac 下 Chrome 浏览器 快捷键

    Chrome窗口和标签页快捷键:Ctrl+N 打开新窗口 Ctrl+T 打开新标签页 Ctrl+Shift+N 在隐身模式下打开新窗口 Ctrl+O,然后选择文件 在谷歌浏览器中打开计算机上的文件 按 ...