/**
题目:UVALive 7721 K - 2-ME Set
链接:https://vjudge.net/problem/UVALive-7721
题意:给定n个数,从中取出一个集合,至少包含两个元素,如果集合内任意两个元素取位与都是0,那么是合法集合。
如果5个数为{5,2,2,1,4}那么有9种。(5, 2), (5, 2), (2, 1), (2, 1, 4), (2, 4), (2, 1), (2, 1, 4), (2, 4), and (1, 4).
问最多有多少种合法集合。
思路:定义dp[i]表示构成集合i的方法数。注意这里的i不是状态压缩那种i,就是纯粹集合内所有的数都满足任意取位与为0,所有数位或起来的。
因为每个数大小最多为20000,从1到20000取位或发现最大为32767。所以dp数组大小为32770. dp[i] += dp[j];(j<i,(j&(i-j))==0) 逆序枚举j。 为了优化时间,相同的数自身和自身不可能在同一个集合,所以统一处理。
然后最终计算结果减去所有的单位集合,即每一个数作为一个集合的情况。 */ #include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
using namespace std;
typedef pair<int,int> P;
typedef long long LL;
const int N = 2e4+;
const int M = ;
const int mod = 1e9+;
const int INF = 0x3f3f3f3f;
int a[N], dp[], s[N], num[N];
struct node
{
int value, cnt;
}t[N];
vector<node> v;
int main()
{
int T, cas = , n;
cin>>T;
while(T--)
{
scanf("%d",&n);
memset(num, , sizeof num);
for(int i = ; i <= n; i++){
scanf("%d",&a[i]);
num[a[i]]++;
}
int m = n;
int n = ;
for(int i = ; i <= ; i++){
if(num[i]){
t[n].cnt = num[i];
t[n].value = i;
n++;
}
}
memset(dp, , sizeof dp);
dp[] = ;
//v.clear();
//v.push_back(node{0,1});
for(int i = ; i < n; i++){
if(i==) s[i] = t[i].value;
else s[i] = s[i-]|t[i].value;
}
for(int i = ; i < n; i++){
for(int j = s[i]; j >= t[i].value; j--){
if((t[i].value&(j-t[i].value))==)
dp[j] = (dp[j]+(LL)dp[j-t[i].value]*t[i].cnt%mod)%mod;
}
}
int ans = ;
for(int i = ; i <= s[n-]; i++) ans = (ans+dp[i])%mod;
printf("Case #%d: %d\n",cas++,(ans-m+mod)%mod);
}
return ;
}

UVALive 7721 K - 2-ME Set 集合dp,所有数的位或来表示状态。的更多相关文章

  1. bzoj2064: 分裂(集合DP)

    ......咸鱼了将近一个月,因为沉迷ingress作业越来越多一直没时间搞OI呜呜呜 题目大意:有一个初始集合(n个元素)和一个目标集合(m个元素)(1<=n,m<=10),两个操作   ...

  2. [UVALive 6661 Equal Sum Sets] (dfs 或 dp)

    题意: 求从不超过 N 的正整数其中选取 K 个不同的数字,组成和为 S 的方法数. 1 <= N <= 20  1 <= K<= 10  1 <= S <= 15 ...

  3. 最大 k 乘积问题 ( 经典区间DP )

    题意 : 设 NUM 是一个 n 位十进制整数.如果将 NUM 划分为 k 段,则可得到 k 个整数.这 k 个整数的乘积称为 NUM 的一个 k 乘积.试设计一个算法,对于给定的 NUM 和 k,求 ...

  4. UVALive - 6257 K - Chemist's vows 【DFS】【BFS】【DP】

    题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  5. uvalive 6669 hidden tree(好壮压dp)

    题目见option=com_onlinejudge&Itemid=8&page=show_problem&problem=4681">here 题意:给一个序列 ...

  6. K - Painful Bases 状压dp

    Painful Bases LightOJ - 1021 这个题目一开始看,感觉有点像数位dp,但是因为是最多有16进制,因为限制了每一个数字都不同最多就有16个数. 所以可以用状压dp,看网上题解是 ...

  7. Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP

    Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10061 ...

  8. UVa 11825 集合dp

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

  9. AGC 005D.~K Perm Counting(容斥 DP 二分图)

    题目链接 \(Description\) 给定\(n,k\),求 满足对于所有\(i\),\(|a_i-i|\neq k\)的排列的个数. \(2\leq n\leq 2000,\quad 1\leq ...

随机推荐

  1. 【leetcode】Binary Tree Postorder Traversal

    题目: Given a binary tree, return the postorder traversal of its nodes' values. For example: Given bin ...

  2. Textarea自动适用高度且无滚动条解决方案

    今日的系统需要动态显示一项数据库里面的内容,该内容包含换行等格式字符,要求如实的反应在页面上. 最初解决办法是使用textarea控件,代码如下: <textarea style="b ...

  3. sip

    INVITE sip:10010101402@10.7.36.70:5060 SIP/2.0 Via: SIP/2.0/UDP 10.7.36.250:5060;rport;branch=z9hG4b ...

  4. JMeter 十二:命令行执行

    参考文档:http://jmeter.apache.org/usermanual/get-started.html#non_gui 真正开始跑压力测试时,我们就不能使用GUI模式了.这时候需要采用命令 ...

  5. Android 蓝牙开发之A2DP基本功能

    本文主要是Android做为Audio Source端,A2DP的基本操作:包括连接.断开连接.设置优先级.获取优先级.获取A2DP连接状态.获取A2DP连接的设备列表等功能. 1.简介 Audio ...

  6. [Unity3D]Unity3D游戏开发之Lua与游戏的不解之缘终结篇:UniLua热更新全然解读

    ---------------------------------------------------------------------------------------------------- ...

  7. Direcshow中视频捕捉和參数设置报告

    Direcshow中视频捕捉和參数设置报告 1.      关于视频捕捉(About Video Capture in Dshow) 1视频捕捉Graph的构建 一个能够捕捉音频或者视频的graph图 ...

  8. H5 Canvas | 画布中变量作用域与setInterval方法同步执行探究

    Demo - 随机绘制圆环 实现思路: 将一个圆环的绘制分成100份,setInterval()方法定义每隔时间n绘制一段新的,每份的开始路径都是上一次的结束路径,实现步进绘制. 通过Math.ran ...

  9. 准备你的Adempiere开发环境(2)- 安装

    1. 用pgAdmin III创建用户adempiere/adempiere:2. 创建adempiere360数据库:3. 导入<ADEMPIERE_HOME>\data\Adempie ...

  10. 【微信小程序】微信小程序wx.previewImage预览图片

    一.小知识 二.例子,配合轮播图使用效果更佳!(如图1) 1.wxml <scroll-view scroll-y="true"> <swiper catchta ...