刘书上例题  关于集合的动态规划

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 200010
#define INF 0x7fffffff
#define inf 10000000
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
using namespace std; int p[20], f[maxn], s[maxn], n; void init()
{
for(int i = 0; i < n; ++ i)
{
p[i] = 1 << i;
int m, x;
scanf("%d", &m);
while(m --)
{
scanf("%d", &x);
p[i] |= (1 << x);
}
}
for(int S = 1; S < (1 << n); ++ S)
{
s[S] = 0;
for(int i = 0; i < n; ++ i) if(S & (1 << i)) s[S] |= p[i];
}
}
int main()
{
int ca = 0;
while(scanf("%d", &n) == 1 && n)
{
init();
int all = (1 << n) - 1;
f[0] = 0;
for(int i = 1; i < (1 << n); ++ i)
{
f[i] = 0;
for(int S = i; S; S = i&(S-1))
if(s[S] == all) f[i] = max(f[i], f[i^S]+1);
}
printf("Case %d: %d\n", ++ ca, f[all]);
}
return 0;
}

uva 11825的更多相关文章

  1. uva 11825 Hackers&#39; Crackdown (状压dp,子集枚举)

    题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪( ...

  2. UVA 11825 - Hackers&#39; Crackdown 状态压缩 dp 枚举子集

    UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:option=com_onlinejudge&Itemid=8&page=sh ...

  3. UVA 11825 Hackers' Crackdown

    题目大意就是有一个图,破坏一个点同时可以破坏掉相邻点.每个点可以破坏一次,问可以完整破坏几次,点数=16. 看到16就想到状压什么的. 尝试设状态:用f[i]表示选的情况是i(一个二进制串),至少可以 ...

  4. UVa 11825 - Hackers' Crackdown DP, 枚举子集substa = (substa - 1)&sta 难度: 2

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  5. UVa 11825 (状压DP) Hackers' Crackdown

    这是我做状压DP的第一道题,状压里面都是用位运算来完成的,只要耐下心来弄明白每次位运算的含义,还是容易理解的. 题意: 有编号为0~n-1的n台服务器,每台都运行着n中服务,每台服务器还和若干台其他服 ...

  6. Hackers' Crackdown( UVA UVA 11825状压dp)

    题意:N台电脑,现在有N种服务,现在你可以在每台电脑终止一项服务,他和他相邻的电脑都会被关闭,如果一项服务在所有电脑都没运行,该项服务成功被破坏,问最多能破坏几种服务. 分析:把n个集合分成尽量多组, ...

  7. [Uva 11825] Hackers’ Crackdown

    Hackers’ Crackdown  Input: Standard Input Output: Standard Output   Miracle Corporations has a numbe ...

  8. UVA 11825 Hackers’ Crackdown(集合动态规划 子集枚举)

    Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...

  9. UVa 11825 集合dp

    #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #i ...

随机推荐

  1. UI4_UIStepper与UIProgressView

    // // ViewController.m // UI4_UIStepper与UIProgressView // // Created by zhangxueming on 15/7/7. // C ...

  2. linux 环境变量的设置【转】

    现在使用linux的朋友越来越多了,在linux下做开发首先就是需要配置环境变量,下面以java环境变量为例介绍三种配置环境变量的方法. 1.修改/etc/profile文件 如果你的计算机仅仅作为开 ...

  3. (转)互联网保险O2O平台微服务架构设计

        关于架构,笔者认为并不是越复杂越好,而是相反,简单就是硬道理也提现在这里.这也是微服务能够流行的原因,看看市场上曾经出现的服务架构:EJB.SCA.Dubbo等等,都比微服务先进,都比微服务功 ...

  4. Java 字节流实现文件读写操作(InputStream-OutputStream)

    Java 字节流实现文件读写操作(InputStream-OutputStream) 备注:字节流比字符流底层,但是效率底下. 字符流地址:http://pengyan5945.iteye.com/b ...

  5. 济南学习 Day 5 T1 pm

    欧拉函数(phi)题目描述: 已知(N),求phi(N). 输入说明: 正整数N. 输出说明: 输出phi(N). 样例输入: 8 样例输出: 4 数据范围: 对于20%的数据,N<=10^5 ...

  6. javascript对象与实例

    var person=new Object(); var person2={}; 一切都是对象 person是Object的实例, 也是对象. 第二个person2也是如此,只不过它是采用字面量的方式 ...

  7. How to modify Code Comments[AX2012]

    // This is a framework class. Customizing this class may cause problems with future upgrades to the ...

  8. 边界函数Bounding Function(成长函数的上界)

    根据成长函数的定义,猜测    -->break point K restricts maximum possible mh(N) a lot for N>k bounding funct ...

  9. SQL Server 数据库身份认证以及包含数据库

    首先分为SQL Server 认证与Windows 身份认证. SQL Server 认证可以运行以下语句来查询 select * from sys.sql_logins 管理员可以直接修改密码,但无 ...

  10. Eclipse 常用插件

    /* ===================== Eclipse Color Theme 语法高亮 ======================== */ 安装方法同上,软件安装URL http:// ...