test20181019 B君的第二题
题意


分析
UPD:以前在口胡,现在重写一下。
这个快速子集和变换其实就是快速莫比乌斯变换。
先做莫比乌斯变换,然后直接组合。这样统计出来的有自己的真子集,直接减去就是了。
再做一个快速超集和变换,这个是拓展内容。
时间复杂度\(O(n2^n)\)
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<complex>
#define rg register
#define il inline
#define co const
#pragma GCC optimize ("O0")
using namespace std;
template<class T> il T read()
{
rg T data=0;
rg int w=1;
rg char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
data=10*data+ch-'0',ch=getchar();
return data*w;
}
template<class T> il T read(rg T&x)
{
return x=read<T>();
}
typedef long long ll;
const int INF=0x7fffffff;
const int MAXN=1<<20|7;
ll f[MAXN];
int main()
{
freopen("lhasa.in","r",stdin);
freopen("lhasa.out","w",stdout);
rg int n,k;
read(n);read(k);
for(rg int i=1;i<=n;++i)
{
++f[read<int>()];
}
for(rg int i=0;i<k;++i) // 逐位递推
for(rg int j=0;j<1<<k;++j)
if(j >> i & 1)
{
f[j] += f[j ^ (1 << i)];
}
for(rg int i=0;i<1<<k;++i) // 组合
{
f[i]=f[i]*(f[i]-1)/2;
}
for(rg int i=0;i<k;++i) // 减去组合成自己的组合
for(rg int j=0;j<1<<k;++j)
if(j >> i & 1)
{
f[j] -= f[j ^ (1 << i)];
}
for(rg int i=0;i<k;++i) // 加上超集的方案数
for(rg int j=0;j<1<<k;++j)
if(j >> i & 1)
{
f[j ^ (1 << i)] += f[j];
}
for(rg int i=0;i<1<<k;++i)
{
printf("%lld\n",f[i]);
}
// fclose(stdin);
// fclose(stdout);
return 0;
}
test20181019 B君的第二题的更多相关文章
- test20181020 B君的第二题
题意 分析 考场70分 一看就是裸的kmp,直接打上去. #include<cstdlib> #include<cstdio> #include<cmath> #i ...
- B 君的第二题 (hongkong)
B 君的第二题 (hongkong) 题目大意: 一个长度为\(n(n\le2\times10^5)\)的数组,给定一个数\(k(k\le40)\).用\(a[i][j]\)表示该数组\(i\)次前缀 ...
- test20181016 B君的第二题
题意 分析 考场暴力50分. 考虑bfs序,一个点的儿子节点的bfs序一定连续,所以对bfs序建线段树,努力打一下就行了. 时间复杂度\(O(n \log n + m \log n)\) #inclu ...
- test20181017 B君的第二题
题意 分析 考场50分 旁边的L君告诉我,求的就是非升子序列的个数,于是写了个树状数组. 但是\(\mod{2333} > 0\)还需要组合数中没有2333的倍数,所以实际上只得了\(a_i \ ...
- test20181015 B君的第二题
题意 分析 考场85分 用multiset暴力,由于教练的机子飞快,有写priority_queue水过了的人. #include<cstdlib> #include<cstdio& ...
- test20181019 B君的第一题
题意 分析 考场做法同标解. 画图模拟分析发现,无论操作顺序怎样,操作数的奇偶性是不变的. 所以等同求出,以每点为根的操作数奇偶性. 用\(f(x)\)表示x及其子树中的边,包括x到它fa的边,将他们 ...
- test20181019 B君的第三题
题意 B 君的第三题(urumqi) 题目描述 风雨如晦,鸡鸣不已. B 君最近在研究自己的学长都在做什么工作,每个学长属于一个公司. B 君会获得一些信息,比如x 和y 在相同公司,x 和y 在不同 ...
- Java蓝桥杯02——第二题集锦:生日蜡烛、星期一、方格计数、猴子分香蕉
第二题 生日蜡烛(结果填空) 某君从某年开始每年都举办一次生日party,并且每次都要吹熄与年龄相同根数的蜡烛. 现在算起来,他一共吹熄了236根蜡烛. 请问,他从多少岁开始过生日party的? 请填 ...
- 05:统计单词数【NOIP2011复赛普及组第二题】
05:统计单词数 总时间限制: 1000ms 内存限制: 65536kB 描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次 ...
随机推荐
- 89. Gray Code(公式题)
The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...
- 39. Combination Sum(回溯)
Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), fin ...
- Yahoo Programming Contest 2019
A - Anti-Adjacency 签. #include <bits/stdc++.h> using namespace std; int main() { int n, k; whi ...
- mongodb-的副本集
复制的重要性不再多说,其主要就是提供数据保护,数据高可用和灾难恢复. 复制是跨多个mongodb服务器分布和维护的方法.mongodb可以把数据从一个节点复制到其他节点并在修改时进行同步. mongo ...
- bzoj1623 / P2909 [USACO08OPEN]牛的车Cow Cars
P2909 [USACO08OPEN]牛的车Cow Cars 显然的贪心. 按速度从小到大排序.然后找车最少的车道,查询是否能填充进去. #include<iostream> #inclu ...
- Linux点亮一个灯
一 文件及其驱动程序 1.解压linux 压缩包 使用命令: tar xzvf linux-3.0.8-20140925.tgz ( tar xvf ------.tar tar xzvf------ ...
- 彻底搞懂DOM事件处理(零)引子
通过合理使用JavaScript,可以为网站用户提供更好的交互体验.这主要是因为JavaScript能够让网站对用户的各种操作及时做出"反馈".这种"反馈"使网 ...
- POJ 2195 Going Home(最小费用最大流)题解
题意:给你一张图,有k个人和k个房子,每个房子只能住一个人,每个人到某一房子的花费为曼哈顿距离,问你让k个人怎么走,使他们都住房子且花费最小. 思路:我们把所有人和超级源点相连,流量为1花费为0,所有 ...
- 使用 p4-graphs 命令将p4程序依赖关系图形化
位置:/home/wasdns/p4factory/targets/l2_switch/p4src 命令: cd /home/wasdns/p4factory/targets/l2_switch/p4 ...
- 使用CAS实现无锁的SkipList
无锁 并发环境下最常用的同步手段是互斥锁和读写锁,例如pthread_mutex和pthread_readwrite_lock,常用的范式为: void ConcurrencyOperation() ...