博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
洛谷P3773 CTSC2017 吉夫特
阅读量:4611 次
发布时间:2019-06-09

本文共 1009 字,大约阅读时间需要 3 分钟。

对于组合数的奇偶性:

根据卢卡斯定理,相当于是在p进制下的分解,对于每一C(n,m),如果n,m不同,那组合数就是偶数

所以组合数C(n,m)为奇数当且仅当 n&m==m

然后就是dp了

设f[i]为以i结尾的方案数

枚举i的子集j,如果j的位置在i的后面且i&j==j,则更新

答案就是所有f[a[i]]的和

#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;const int maxn = 255555;const int mod = 1e9+7;int n,m,up,ans;int a[maxn],c[maxn];int f[maxn]; // 以i为结尾 ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f;}int main(){ n=read(); for(int i=1;i<=n;++i) a[i]=read(),c[a[i]]=i,up=max(up,a[i]),f[a[i]]=1; for(int i=1;i<=n;++i){ for(int j=(a[i]-1)&a[i];j;j=(j-1)&a[i]){ // 枚举子集 if(c[j]>i){ if((a[i]&j)==j) f[j]=(f[j]+f[a[i]])%mod; } } } for(int i=1;i<=n;i++){ ans=(ans+f[a[i]]-1)%mod; } printf("%d\n",ans); return 0;}

 

转载于:https://www.cnblogs.com/tuchen/p/10415486.html

你可能感兴趣的文章
Perl last和next的用法区别
查看>>
Selenium 管理 Cookies
查看>>
exceptionfunction[LeetCode]Permutations
查看>>
Linux(2)_常用命令2
查看>>
自定义分页
查看>>
[转]DELPHI——调试(1)
查看>>
JS秒数转成分秒时间格式
查看>>
xp_cmdshell 命令的开启与关闭,和状态查询
查看>>
Linux sudoers
查看>>
MySQL详解(18)-----------分页方法总结
查看>>
bzoj 4595 激光发生器
查看>>
multi cookie & read bug
查看>>
js时间转换
查看>>
(转载) Android Studio你不知道的调试技巧
查看>>
队列实现霍夫曼树
查看>>
JAVA 笔记(一)
查看>>
{Nodejs} request URL 中文乱码
查看>>
异常及日志使用与项目打包
查看>>
努力,时间,坚持,自律
查看>>
数组相关函数
查看>>