895C
来源:互联网 发布:java 异或加密 字符串 编辑:程序博客网 时间:2024/06/04 00:33
因为其给的a的数据范围较小,70 ,又其是求平方数,所以考虑质数分解.
其质数只有19个,考虑状压DP
由于n为100000,复杂度太大,考虑离散化
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int N=1e5+5;const int MOD=1e9+7;int a[N];int cnt[75];//离散化ll dp[2][(1<<19)+1];ll er[N];int s[75];int prime[19]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67};int main(){// freopen("data.txt","r",stdin); ios::sync_with_stdio(false); for(int i=1;i<=70;i++) { int t=i; for(int j=0;j<19;j++) { while(t%prime[j]==0)t/=prime[j],s[i]^=(1<<j); } } er[0]=1; for(int i=1;i<N;i++)er[i]=(er[i-1]*2)%MOD; int n; cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; cnt[a[i]]++; } dp[0&1][0]=1; for(int i=1;i<=70;i++) { if(!cnt[i]) { for(int j=0;j<(1<<19);j++) { dp[i&1][j]=dp[(i+1)&1][j]; } } else { for(int j=0;j<(1<<19);j++) { dp[i&1][j]=0; } for(int j=0;j<(1<<19);j++) { dp[i&1][j^s[i]]=(dp[i&1][j^s[i]]+er[cnt[i]-1]*dp[(i+1)&1][j])%MOD;//从cnt[i]个数个选奇数个,C(n,1)+C(n,3)+...=2^(n-1) dp[i&1][j]=(dp[i&1][j]+er[cnt[i]-1]*dp[(i+1)&1][j])%MOD;//从cnt[i]个数个选偶数个,C(n,0)+C(n,2)*C(n,4)+...=2^(n-1) } } } cout<<(dp[70&1][0]-1)%MOD<<endl;//减去0的情况 return 0;}
阅读全文
0 0
- 895C
- 895C
- Codeforces 895C(状压)
- Codeforces 895C
- codeforces 895C
- c
- c
- c
- c
- C
- c
- c
- c
- C+
- c
- C
- c
- c
- 安卓动画的简单实现方法(Animation和AnimationDrawable)
- eclipse安装插件注意事项
- [Java面试六]SpringMVC总结以及在面试中的一些问题
- 浏览器多个标签页通信
- 十分钟入门RocketMQ
- 895C
- (一)Angular 快速入门
- autocomplete自动填充
- 第十一周项目4
- 【设计模式】空对象模式(Null Object Pattern)
- RecyclerView Item 布局宽高无效问题探究
- 破解win2003“终端服务器授权”激活许可证!
- [转]addWeighted() 对两幅图像进行融合
- Spring boot 消费kafka 写入hbase