codeforces895C Square Subsets
来源:互联网 发布:php $_file 编辑:程序博客网 时间:2024/06/06 08:40
什么,这是状压DP???
是在下输了…输的心服口服…
ABC都是好题啊…
前排提醒,由于latex没有^这个符号,所以用
首先看看数据范围,70这个玄学范围,emmm…
理性分析查找题解一波,我们想起来要的是完全平方数,那么就可以搞一些大新闻:
用
由于
首先我们需要知道一条结论:
那么我们可以预处理出来
对于某个数
如果
否则有两种选择,一种是选择奇数个
这是因为在这种情况下,异或奇数次相当于异或一次,所以这就是求解n个数里选奇数个的情况总和,带入公式(1)即可;
另一种是选择偶数个
然后这道题就做完啦!不过注意一个细节,这里不小心将0这种情况算了进去,所以还要-1。
另外开LL数组会爆空间。。
AC代码:(mmp调了半天发现质数表写错了。。)
#include <iostream>#include <cstdio>#include <cctype>#include <algorithm>using namespace std;typedef long long LL;inline LL read(LL &x) { x = 0; char c = getchar(); while(!isdigit(c)) c = getchar(); while(isdigit(c)) x = x * 10 + c - '0', c = getchar();}const LL MOD = 1e9+7;int prime[19] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67};int s[73], cnt[73], powmod[100003], dp[73][(1 << 19)];inline void fenjie(LL x) { int t = x; //cout<<x<<" "; for(int j = 0; j < 19; ++j) { //cout<<x<<" "<<prime[i]<<endl; while(t % prime[j] == 0) s[x] ^= (1 << j), t /= prime[j]; }}int main() { //freopen("pai.txt", "w", stdout); LL n; read(n); LL tmp; for(int i = 1; i <= 70; ++i) fenjie(i); //for(int i = 1; i <= 70; ++i) cout<<s[i]<<endl; for(int i = 1; i <= n; ++i) read(tmp), cnt[tmp]++; powmod[0] = 1; for(int i = 1; i <= n; ++i) powmod[i] = ((1LL) * powmod[i - 1] * 2) % MOD; dp[0][0] = 1; for(int i = 1; i <= 70; ++i) { if(!cnt[i]) for(int j = 0; j < (1 << 19); ++j) dp[i][j] = dp[i - 1][j]; else for(int j = 0; j < (1 << 19); ++j) { dp[i][j ^ s[i]] = ((1LL)*dp[i][j ^ s[i]] + (1LL)*powmod[cnt[i] - 1] * dp[i - 1][j]) % MOD; dp[i][j] = ((1LL)*dp[i][j] + (1LL)*powmod[cnt[i] - 1] * dp[i - 1][j]) % MOD; } } //cout<<dp[1][0]<<endl; cout<<(dp[70][0] - 1) % MOD<<endl; return 0;}
参考资料:
https://www.cnblogs.com/widsom/p/7910385.html
https://www.cnblogs.com/chinacwj/p/7967796.html
阅读全文
0 0
- Codeforces895C. Square Subsets
- codeforces895C Square Subsets
- cf 895C Square Subsets
- CF895C:C. Square Subsets(状压dp)
- codeforces 895C Square Subsets 线性基 或 状压DP
- Codeforces Round #448 (Div. 2) C. Square Subsets
- Codeforces Round #448 (Div. 2) C. Square Subsets
- CF 895C. Square Subsets DP(状压,平方数)
- Codeforces Round #448 (Div. 2) C. Square Subsets
- Codeforces Round #448 (Div. 2) C. Square Subsets(状压)
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- 机器学习---支持向量机(SVM)算法应用(下)
- 这两天项目所遇到的知识点
- AT&T风格与Intel风格的x86汇编语法区别
- Java虚拟机JVM
- jsp_自动加载与Config对象
- codeforces895C Square Subsets
- 基于goEasy消息推送的扫码登录
- JavaWeb后端工程师技能图
- LeetCode 42. Trapping Rain Water
- 找出数组中元素的位置
- 动态几何
- 福布斯:首个1000亿美元区块链公司可能成为下一个SAP
- Condition入门
- 在什么情况下使用null和undefined