题目传送门

  戳此处转移

题目大意

  给定一个长为$n$的序列,问它有多少个长度大于等于2的子序列$b_{1}, b_{2}, \cdots, b_{k}$满足$\prod_{i = 2}^{k}C_{b_{i - 1}}^{b_{i}} \equiv 1 \pmod{2}$。答案模$10^{9} + 7$

  考虑限制条件,即前后两个数$b_{i - 1}, b_{i}$,它们要满足$C_{b_{i - 1}}^{b_{i}} \equiv 1\pmod{2}$。

  这样不好处理,考虑使用Lucas定理,得到$b_{i - 1}$是$b_{i}$的子集的结论。

  然后是个常规动态规划,用$f[i][s]$表示考虑到第$i$位,最后一个数是$s$的方案数。但是这样时间复杂度$O(n^{2})$。

  考虑分块,每个位置将它的子集信息上传。

  然后修改和查询一个枚举前9位,一个枚举后9位就行了。

  一直不知道所有数互不相同的意义。

  然后直到今天,发现可以直接枚举子集,$O(3^{\left \lceil \log_{2}W \right \rceil})$。

Code

 /**
* uoj
* Problem#300
* Accepted
* Time: 400ms
* Memory: 2956k
*/
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean; const int S = << , M = 1e9 + ;
const int maskL = ( << ) - , maskH = maskL << , mask = maskL | maskH; int n;
int *ar;
int f[S][S]; inline void init() {
scanf("%d", &n);
ar = new int[(n + )];
for (int i = ; i <= n; i++)
scanf("%d", ar + i);
} inline int query(int S) {
int rt = , s0 = S & maskL, s1 = (S & maskH) >> , ms1 = s1 ^ maskL;
for (int s = ms1; s; s = (s - ) & ms1)
rt = (rt + f[s | s1][s0]) % M;
return (rt + f[s1][s0]) % M;
} inline void modify(int S, int val) {
int s0 = S & maskL, s1 = (S & maskH) >> ;
for (int s = s0; s; s = (s - ) & s0)
f[s1][s] = (f[s1][s] + val) % M;
f[s1][] = (f[s1][] + val) % M;
} int res = ; inline void solve() {
modify(mask, );
for (int i = , c; i <= n; i++) {
c = query(ar[i]);
res = (res + c) % M;
modify(ar[i], c);
}
res = (res - n + M) % M;
printf("%d", res);
} int main() {
// freopen("gift.in", "r", stdin);
init();
solve();
return ;
}

uoj 300 [CTSC2017]吉夫特 - Lucas - 分块 - 动态规划的更多相关文章

  1. 【BZOJ4903】【UOJ#300】吉夫特(卢卡斯定理,动态规划)

    [BZOJ4903][UOJ#300]吉夫特(卢卡斯定理,动态规划) 题面 UOJ BZOJ:给的UOJ的链接...... 题解 首先模的质数更小了,直接给定了\(2\).当然是卢卡斯定理了啊. 考虑 ...

  2. loj 300 [CTSC2017]吉夫特 【Lucas定理 + 子集dp】

    题目链接 loj300 题解 orz litble 膜完题解后,突然有一个简单的想法: 考虑到\(2\)是质数,考虑Lucas定理: \[{n \choose m} = \prod_{i = 1} { ...

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

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

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

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

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

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

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

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

  7. BZOJ4903 UOJ300 CTSC2017 吉夫特 【Lucas定理】

    BZOJ4903 UOJ300 CTSC2017 吉夫特 弱弱地放上题目链接 Lucas定理可以推一推,发现C(n,m)是奇数的条件是n" role="presentation&q ...

  8. [UOJ300][CTSC2017]吉夫特

    uoj bzoj luogu sol 根据\(Lucas\)定理,\(\binom nm \mod 2=\binom{n\%2}{m\%2}\times\binom{n/2}{m/2}\mod 2\) ...

  9. uoj#300.【CTSC2017】吉夫特

    题面:http://uoj.ac/problem/300 一道大水题,然而我并不知道$lucas$定理的推论.. $\binom{n}{m}$为奇数的充要条件是$n&m=n$.那么我们对于每个 ...

随机推荐

  1. unity3d 第一人称脚本解释MouseLook

    using UnityEngine; using System.Collections; /// MouseLook rotates the transform based on the mouse ...

  2. css抖动动画

    button{ animation: beat 6s ease 0s infinite normal; } @keyframes beat { 0% { transform: translateY(0 ...

  3. vsftp

    [安装vsftpd]安装vsftpd工具步骤   1 安装vsftpd组件 [root@bogon ~]# yum -y install vsftpd 安装完后,有/etc/vsftpd/vsftpd ...

  4. CSS radial-gradient() 函数实现渐变

    值 描述 shape 确定圆的类型: ellipse (默认): 指定椭圆形的径向渐变. circle :指定圆形的径向渐变 size 定义渐变的大小,可能值: farthest-corner (默认 ...

  5. Vue系列之 => 使用钩子函数的第二个参数传参

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. E. Kefa and Watch hash 线段树

    2015-09-28 14:11:36 by opas 这题给的是一个字符串 把其中一些子串给取出来 判断是否是周期为d的字符串  还需要把 其中的一个区间完全变成一个数 ,然后在查询,我们把每个字符 ...

  7. CSS选择符-----属性选择符

       Element[att] 选择具有att属性的E元素 <!DOCTYPE html> <html> <head> <meta charset=" ...

  8. 【Linux学习六】用户管理

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 一.增加删除用户或组新增用户useradd scott修改用户密码pa ...

  9. C/C++笔试题(编程题)

    面试过程中遇到的编程题整理,于此备录.分享,共勉.(持续更新中......欢迎补充) (1)用户输入M, N值,从1至N开始顺序循环数数,每数到M输出该数值,直至全部输出.写出C程序. 程序代码如下: ...

  10. 理解本真的 REST 架构风格

    1. http://kb.cnblogs.com/page/186516/ 2. http://www.infoq.com/cn/articles/rest-introduction 3. http: ...