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 描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次 ...
随机推荐
- python webdriver 登录163邮箱发邮件加附件, 外加数据和程序分离,配置文件的方式
配置文件:UiObjectMapSendMap.ini用来存放配置信息 GetOptionSendMail.py 用来读取配信息 #encoding=utf-8from selenium.webdri ...
- linux 常用命令总结(一)
1. 字符串常用命令: 替换: 1). %s/*/*/g 中,替换当前界面的所有符合规则的内容. 2). 替换文件中的字符串内容: find -name '要查找的文件名' | xargs ...
- 基于Policy Gradient实现CartPole
http://chenrudan.github.io/blog/2016/09/04/cartpole.html 首页 分类 关于 归档 标签 基于Policy Gradient实现CartPole ...
- TED #05# How we can face the future without fear, together
Rabbi Lord Jonathan Sacks: How we can face the future without fear, together 1. what was it like bei ...
- SQL学习笔记七之MySQL视图、触发器、事务、存储过程、函数
阅读目录 一 视图 二 触发器 三 事务 四 存储过程 五 函数 六 流程控制 一 视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名 ...
- usb_control_msg() -- 从设备读取各种信息
et_port_status() --> usb_control_msg()usb_get_descriptor() --> usb_control_msg()/usr/src/linux ...
- spring Boot加载bean
1.SpringBoot中加载bean,可以使用注解@compenent直接加载到applicationContext容器中 2.在直接类@Configuration中,手动注册bean,如:
- OpenDayLight Helium安装
参照:OpenDaylight的Helium(氦)版本安装 下载链接地址为 http://www.opendaylight.org/software/downloads/helium 安装: unzi ...
- Java网络编程和NIO详解1:JAVA 中原生的 socket 通信机制
Java网络编程和NIO详解1:JAVA 中原生的 socket 通信机制 JAVA 中原生的 socket 通信机制 摘要:本文属于原创,欢迎转载,转载请保留出处:https://github.co ...
- bzoj-4565-区间dp+状压
4565: [Haoi2016]字符合并 Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 542 Solved: 253[Submit][Status ...