bzoj4903 & loj2264 [Ctsc2017]吉夫特 Lucas 定理+状压DP
题目传送门
https://lydsy.com/JudgeOnline/problem.php?id=4903
题解
真 - 签到题。
对于一个组合数,直接进行 Luca 定理。
\]
可以发现,对于每一个二进制位,如果出现 \((0, 1)\) 这样的组合,那么整个组合数就是 \(0\),否则就是 \(1\)。
所以 \(\binom nm = 1\) 的充要条件就是 \(m \subseteq n\)。
那么把问题放到序列上,对于一位求出答案以后,扫描其所有子集更新。
因为 \(a_i\) 两两不同,所以复杂度可以保证为 \(O(3^{\log_2 a_i})\)。
#include<bits/stdc++.h>
#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back
template<typename A, typename B> inline char smax(A &a, const B &b) {return a < b ? a = b, 1 : 0;}
template<typename A, typename B> inline char smin(A &a, const B &b) {return b < a ? a = b, 1 : 0;}
typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii;
template<typename I> inline void read(I &x) {
int f = 0, c;
while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
x = c & 15;
while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
f ? x = -x : 0;
}
const int N = 211985 + 7;
const int M = 233333 + 7;
const int P = 1e9 + 7;
int n, m;
int a[N], dp[M];
inline int smod(int x) { return x >= P ? x - P : x; }
inline void sadd(int &x, const int &y) { x += y; x >= P ? x -= P : x; }
inline int fpow(int x, int y) {
int ans = 1;
for (; y; y >>= 1, x = (ll)x * x % P) if (y & 1) ans = (ll)ans * x % P;
return ans;
}
inline void work() {
int ans = 0;
for (int i = 1; i <= m; ++i) dp[i] = 1;
for (int i = 1; i <= n; ++i) {
int s = a[i];
sadd(ans, dp[s] - 1);
int tmp = dp[s];
for (int sta = s; sta; sta = (sta - 1) & s) sadd(dp[sta], tmp);
}
printf("%d\n", ans);
}
inline void init() {
read(n);
for (int i = 1; i <= n; ++i) read(a[i]), smax(m, a[i]);
}
int main() {
#ifdef hzhkk
freopen("hkk.in", "r", stdin);
#endif
init();
work();
fclose(stdin), fclose(stdout);
return 0;
}
bzoj4903 & loj2264 [Ctsc2017]吉夫特 Lucas 定理+状压DP的更多相关文章
- [CTSC2017]吉夫特(Lucas定理,DP)
送70分,预处理组合数是否为偶数即可. 剩下的数据,根据Lucas定理的推论可得当且仅当n&m=n的时候,C(n,m)为奇数.这样就可以直接DP了,对于每个数,考虑它对后面的数的影响即可,直接 ...
- 洛谷P3773 [CTSC2017]吉夫特(Lucas定理,dp)
题意 满足$b_1 < b_2 < \dots < b_k$且$a_{b_1} \geqslant a_{b_2} \geqslant \dots \geqslant a_{b_k} ...
- 『Exclusive Access 2 dilworth定理 状压dp』
Exclusive Access 2 Description 给出 N 个点M 条边的无向图,定向得到有向无环图,使得最长路最短. N ≤ 15, M ≤ 100 Input Format 第一行一个 ...
- 【Codeforces】Gym 101173B Bipartite Blanket 霍尔定理+状压DP
题意 给一张$n\times m$二分图,带点权,问有多少完美匹配子集满足权值和大于等于$t$ 这里有一个结论:对于二分图$\mathbb{A}$和$\mathbb{B}$集合,如果子集$A \in ...
- BZOJ4903 UOJ300 CTSC2017 吉夫特 【Lucas定理】
BZOJ4903 UOJ300 CTSC2017 吉夫特 弱弱地放上题目链接 Lucas定理可以推一推,发现C(n,m)是奇数的条件是n" role="presentation&q ...
- 【bzoj4903/uoj300】[CTSC2017]吉夫特 数论+状压dp
题目描述 给出一个长度为 $n$ 的序列,求所有长度大于等于2的子序列个数,满足:对于子序列中任意两个相邻的数 $a$ 和 $b$ ($a$ 在 $b$ 前面),${a\choose b}\mod 2 ...
- HDU 1565&1569 方格取数系列(状压DP或者最大流)
方格取数(2) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- 【XSY2745】装饰地板 状压DP 特征多项式
题目大意 你有\(s_1\)种\(1\times 2\)的地砖,\(s_2\)种\(2\times 1\)的地砖. 记铺满\(m\times n\)的地板的方案数为\(f(m,n)\). 给你\(m, ...
- 7月15日考试 题解(链表+状压DP+思维题)
前言:蒟蒻太弱了,全打的暴力QAQ. --------------------- T1 小Z的求和 题目大意:求$\sum\limits_{i=1}^n \sum\limits_{j=i}^n kth ...
随机推荐
- luoguP3806 【模板】点分治1
#include<bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) #define ...
- 用soapUI开发webservice接口
1,下载soapUI软件,安装到本地 2,打开soapUI软件 3,创建一个开发好的接口 4,进行接口调用 测试:
- .HDF数据库与SQLSERVER / ORACLE的区别
无论ArcGIS的.gbd文件还是MapGIS的.hdf文件,都是数据库文件. 后缀是无意义的.有意义的是其中内在的逻辑和数据结构. https://zhidao.baidu.com/question ...
- UE4-PS4开发渲染线程优化方法及记录
先说方法: Launch 到 PS4 Devkit上,在PS4上输入Stat unit 看瓶颈在哪里.我们发现Frame 和Draw数值几乎一样,其余两项相对较小,这表明瓶颈在渲染线程上. 关于渲染线 ...
- 牛客多校第一场 Random Point in Triangle
https://ac.nowcoder.com/acm/contest/881/F 打表代码: #include<bits/stdc++.h> using namespace std; ] ...
- Java实践-远程调用Shell脚本并获取输出信息
1.添加依赖 <dependency> <groupId>ch.ethz.ganymed</groupId> <artifactId>ganymed-s ...
- cordova+vue做的app解决引入cordova-plugin-splashscreen后启动先显示黑屏在显示启动页
先上项目目录结构cordova项目结构 android platform 结构 图中用红框框起来的为主要修改文件 这篇主要的讲cordova项目引用了cordova-plugin-splashscre ...
- custom serializer for just one property in Json.NET
Json序列化的时候跳过加密字段 字段类定义如下 public class Field { public bool IsEncrypted { get; set; } public string Na ...
- python 数值系列-进制转换
进制转换 前语: 如果您不通二进制,八进制,十六进制,请移步:http://www.360doc.com/content/17/0211/21/40101294_628326994.shtml 问题 ...
- 通过VLC的ActiveX进行二次开发,实现一个多媒体播放器 2011-04-10 00:57:23
http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=25498312&id=218294 通过VLC的ActiveX进行二 ...