题意



分析

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君的第二题的更多相关文章

  1. test20181020 B君的第二题

    题意 分析 考场70分 一看就是裸的kmp,直接打上去. #include<cstdlib> #include<cstdio> #include<cmath> #i ...

  2. B 君的第二题 (hongkong)

    B 君的第二题 (hongkong) 题目大意: 一个长度为\(n(n\le2\times10^5)\)的数组,给定一个数\(k(k\le40)\).用\(a[i][j]\)表示该数组\(i\)次前缀 ...

  3. test20181016 B君的第二题

    题意 分析 考场暴力50分. 考虑bfs序,一个点的儿子节点的bfs序一定连续,所以对bfs序建线段树,努力打一下就行了. 时间复杂度\(O(n \log n + m \log n)\) #inclu ...

  4. test20181017 B君的第二题

    题意 分析 考场50分 旁边的L君告诉我,求的就是非升子序列的个数,于是写了个树状数组. 但是\(\mod{2333} > 0\)还需要组合数中没有2333的倍数,所以实际上只得了\(a_i \ ...

  5. test20181015 B君的第二题

    题意 分析 考场85分 用multiset暴力,由于教练的机子飞快,有写priority_queue水过了的人. #include<cstdlib> #include<cstdio& ...

  6. test20181019 B君的第一题

    题意 分析 考场做法同标解. 画图模拟分析发现,无论操作顺序怎样,操作数的奇偶性是不变的. 所以等同求出,以每点为根的操作数奇偶性. 用\(f(x)\)表示x及其子树中的边,包括x到它fa的边,将他们 ...

  7. test20181019 B君的第三题

    题意 B 君的第三题(urumqi) 题目描述 风雨如晦,鸡鸣不已. B 君最近在研究自己的学长都在做什么工作,每个学长属于一个公司. B 君会获得一些信息,比如x 和y 在相同公司,x 和y 在不同 ...

  8. Java蓝桥杯02——第二题集锦:生日蜡烛、星期一、方格计数、猴子分香蕉

    第二题 生日蜡烛(结果填空) 某君从某年开始每年都举办一次生日party,并且每次都要吹熄与年龄相同根数的蜡烛. 现在算起来,他一共吹熄了236根蜡烛. 请问,他从多少岁开始过生日party的? 请填 ...

  9. 05:统计单词数【NOIP2011复赛普及组第二题】

    05:统计单词数 总时间限制:  1000ms 内存限制:  65536kB 描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次 ...

随机推荐

  1. Spring—spring概述

    Spring框架的特点? 1:轻量级,一站式开发 2:易用,追求代码的最佳实现 3:Spring的内容: a:Ioc容器 b:AOP实现 c:数据访问支持(ORM框架/声明事务[Transaction ...

  2. JavaScript实现Map功能

    JavaScript中没有类似Java中的Map集合类的实现,自己做了简单实现,如下: function Map() { this.elements = new Array(); this.size= ...

  3. Python3基础 print 自带换行

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  4. cuda8.0 出错:/usr/bin/ld: 找不到 -lGL【转】

    本文转自:https://blog.csdn.net/u010159842/article/details/56833030 最近在学习深度学习,在搭建CUDA8.0的时候,出现一个非常不好的问题: ...

  5. CGI, FCGI, SCGI, WSGI 释异

    IKI Links: CGI - http://en.wikipedia.org/wiki/Common_Gateway_Interface FCGI - http://en.wikipedia.or ...

  6. Flask: socket.error: [Errno 48] Address already in use 问题

    参考: Mac OSX 解决socket.error: [Errno 48] Address already in use问题 Mac OS X中解决socket.error: [Errno 48] ...

  7. 基于spring boot admin 做监控的一些问题记录

    问题一 各个健康节点权限问题 解决方式 加入权限模块 <dependency> <groupId>org.springframework.boot</groupId> ...

  8. 51Nod 1737 配对(树的重心)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1737 题意: 思路: 树的重心. 树的重心就是其所以子树的最大的子树结点 ...

  9. php while循环

    <html> <body> <?php $i=; ) { echo "The number is " . $i . "<br>& ...

  10. php 数值数组

    <?php $cars=array("Volvo","BMW","Toyota"); echo ] . ] . ] . ". ...