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.

输入描述:

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的更多相关文章

  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. Java 高级面试知识点汇总!

    1.常用设计模式 单例模式:懒汉式.饿汉式.双重校验锁.静态加载,内部类加载.枚举类加载.保证一个类仅有一个实例,并提供一个访问它的全局访问点. 代理模式:动态代理和静态代理,什么时候使用动态代理. ...

  2. <数据可视化>Matplotlib(2D+3D)

    1.Matplotlib介绍(2D) Matplotlib 是 Python 2D-绘图领域使用最广泛的套件.它能让使用者很轻松地将数据图形化,并且提供多样化的输出格式. pylab 是 matplo ...

  3. <day004>小娜显示空白+CSV文件的基本操作+普通的代理使用

    小知识: 当小娜搜索显示空白的时候,怎么解决? 任务管理器结束小娜进程就好了= =*(多半是惯得,关掉就好了!) 任务1:CSV文件的基本操作 import csv import pandas as ...

  4. Startup里面的一些用法

    using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; usi ...

  5. 收藏的链接-Qt

    Qt编写的开源帖子集合(懒人专用) - QTCN开发网 - Powered by phpwind http://www.qtcn.org/bbs/read-htm-tid-85501.html?tds ...

  6. 洛谷P3834【模板】可持久化线段树 1(主席树)

    题目背景 这是个非常经典的主席树入门题--静态区间第K小 数据已经过加强,请使用主席树.同时请注意常数优化 题目描述 如题,给定N个正整数构成的序列,将对于指定的闭区间查询其区间内的第K小值. 输入输 ...

  7. Python中死锁的形成示例及死锁情况的防止

    死锁示例搞多线程的经常会遇到死锁的问题,学习操作系统的时候会讲到死锁相关的东西,我们用Python直观的演示一下.死锁的一个原因是互斥锁.假设银行系统中,用户a试图转账100块给用户b,与此同时用户b ...

  8. 点击回退时需要点击2次才可返回js

    为a加上window.location.href跳转页面时,再返回到此页面,再点击返回时需点击2次才能返回到前一个页面,原因竟然是href=“#”的原因,在html中#可做为锚点 http://blo ...

  9. 深入浅出 Java Concurrency (34): 线程池 part 7 线程池的实现及原理 (2)[转]

    线程池任务执行流程 我们从一个API开始接触Executor是如何处理任务队列的. java.util.concurrent.Executor.execute(Runnable) Executes t ...

  10. 6大主流开源SQL引擎总结,遥遥领先的是谁?

    根据 O’Reilly 2016年数据科学薪资调查显示,SQL 是数据科学领域使用最广泛的语言.大部分项目都需要一些SQL 操作,甚至有一些只需要SQL.本文就带你来了解这些主流的开源SQL引擎!背景 ...