题目链接

loj300

题解

orz litble

膜完题解后,突然有一个简单的想法:

考虑到\(2\)是质数,考虑Lucas定理:

\[{n \choose m} = \prod_{i = 1} {\lfloor \frac{n}{2^{i - 1}} \rfloor \mod 2^i \choose \lfloor \frac{m}{2^{i - 1}} \rfloor \mod 2^i} \pmod 2
\]

\[{n \choose m} = \prod_{each.bit.of.n.and.m} {n' \choose m'} \pmod 2
\]

如果二进制下有任何一位\(n\)为\(0\)且\(m\)不为\(0\),那么就会出现\(m' > n'\)的项,结果就为\(0\)了

所以结果不为\(0\),当且仅当二进制下\(m\)是\(n\)的子集

所以枚举子集dp即可【\(f[i]\)表示以\(A[u] = i\)的\(u\)开头的合法子序列个数】

\([1,n]\)枚举子集的复杂度是\(O(3^{log(max\{a_i\})})\)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define LL long long int
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define BUG(s,n) for (int i = 1; i <= (n); i++) cout<<s[i]<<' '; puts("");
using namespace std;
const int maxn = 250000,maxm = 100005,INF = 1000000000,P = 1e9 + 7;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
int f[maxn],a[maxn],ans,n;
int main(){
n = read();
REP(i,n) a[i] = read();
for (int i = n; i; i--){
int u = a[i];
for (int j = u; j; j = (j - 1) & u){
f[u] = (f[u] + f[j]) % P;
}
ans = (ans + f[u]) % P;
f[u]++;
}
printf("%d\n",ans);
return 0;
}

loj 300 [CTSC2017]吉夫特 【Lucas定理 + 子集dp】的更多相关文章

  1. uoj 300 [CTSC2017]吉夫特 - Lucas - 分块 - 动态规划

    题目传送门 戳此处转移 题目大意 给定一个长为$n$的序列,问它有多少个长度大于等于2的子序列$b_{1}, b_{2}, \cdots, b_{k}$满足$\prod_{i = 2}^{k}C_{b ...

  2. [CTSC2017]吉夫特(Lucas定理,DP)

    送70分,预处理组合数是否为偶数即可. 剩下的数据,根据Lucas定理的推论可得当且仅当n&m=n的时候,C(n,m)为奇数.这样就可以直接DP了,对于每个数,考虑它对后面的数的影响即可,直接 ...

  3. 洛谷P3773 [CTSC2017]吉夫特(Lucas定理,dp)

    题意 满足$b_1 < b_2 < \dots < b_k$且$a_{b_1} \geqslant a_{b_2} \geqslant \dots \geqslant a_{b_k} ...

  4. bzoj4903 & loj2264 [Ctsc2017]吉夫特 Lucas 定理+状压DP

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4903 https://loj.ac/problem/2264 http://uoj.ac/pr ...

  5. uoj86 mx的组合数 (lucas定理+数位dp+原根与指标+NTT)

    uoj86 mx的组合数 (lucas定理+数位dp+原根与指标+NTT) uoj 题目描述自己看去吧( 题解时间 首先看到 $ p $ 这么小还是质数,第一时间想到 $ lucas $ 定理. 注意 ...

  6. BZOJ.4903.[CTSC2017]吉夫特(Lucas DP)

    题目链接 首先\(C(n,m)\)为奇数当且仅当\(n\&m=m\). 简要证明: 因为是\(mod\ 2\),考虑Lucas定理. 在\(mod\ 2\)的情况下\(C(n,m)\)最后只会 ...

  7. 【bzoj4903/uoj300】[CTSC2017]吉夫特 数论+状压dp

    题目描述 给出一个长度为 $n$ 的序列,求所有长度大于等于2的子序列个数,满足:对于子序列中任意两个相邻的数 $a$ 和 $b$ ($a$ 在 $b$ 前面),${a\choose b}\mod 2 ...

  8. bzoj 1902: Zju2116 Christopher lucas定理 && 数位DP

    1902: Zju2116 Christopher Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 172  Solved: 67[Submit][Stat ...

  9. BZOJ4737 组合数问题 【Lucas定理 + 数位dp】

    题目 组合数C(n,m)表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3)三个物品中选择两个物品可以有( 1,2),(1,3),(2,3)这三种选择方法.根据组合数的定义,我们可以给 ...

随机推荐

  1. MicroService 微服务提供者搭建

    本机IP为  192.168.1.102 1.  新建Maven项目   microservice 2.   pom.xml <project xmlns="http://maven. ...

  2. install cmake,install torch7

    cmake http://blog.csdn.net/jesse__zhong/article/details/21290675 torch7 http://wanghaitao8118.blog.1 ...

  3. Bootstrap 历练实例 - 折叠(Collapse)插件方法

    方法 下面是一些折叠(Collapse)插件中有用的方法: 方法 描述 实例 Options:.collapse(options) 激活内容为可折叠元素.接受一个可选的 options 对象. $(' ...

  4. python 使用requests 请求 https 接口 ,取消警告waring

    response = requests.request("POST", url, timeout=20, data=payload, headers=headers, proxie ...

  5. OpenFaceswap 入门教程(2):软件使用篇!

    安装完OpenFaceswap之后,是不是就迫不及待的想要“见证奇迹”了呢? 都说磨刀不误砍柴工.开始之前请先做一个准备.然后大致了解一下换脸的过程 换脸基本步骤是: 把视频切成很多图片 把图片中的人 ...

  6. JZOJ 5838. 旅游路线 最大子段和

    5838. 旅游路线 Time Limits: 1000 ms  Memory Limits: 131072 KB  Detailed Limits   Goto ProblemSet Descrip ...

  7. 809. Expressive Words

    https://leetcode.com/problems/expressive-words/description/ class Solution { public: int expressiveW ...

  8. printf("\033[1;33m ***** \033[0m \n");

    printf("\033[1;33m Hello World. \033[0m \n"); 颜色如下: none = "\033[0m" black = &qu ...

  9. POJ 3370 Halloween treats(抽屉原理)

    Halloween treats Every year there is the same problem at Halloween: Each neighbour is only willing t ...

  10. 命令执行sql

    从外网把数据库用导出脚本的方式导出来了,280M的样子,导是导出来了,但是在本机执行sql脚本的时候,直接就是out of memory,之前执行60M的脚本没出过这问题,直接双击打开.sql脚本文件 ...