codeforces 895C
来源:互联网 发布:淘宝退款不退货会怎样 编辑:程序博客网 时间:2024/05/19 01:08
(状压dp)
题意:给定一个集合,里面包括
思路:观察到
当
当
代码:
#include <iostream>#include <cstdio>#include <vector>#include <cstring>#include <algorithm>#define LL long longusing namespace std;const int maxn = 100050;const LL mod = 1e9 + 7;LL dp[2][1<<19], pw[maxn];int a[maxn], cnt[80], bitmask[80];vector<int> prim;void init() { // get 2^n pw[0] = 1; for(int i=1; i<maxn; i++) pw[i] = 2LL * pw[i-1] % mod; prim.clear(); memset(cnt, 0, sizeof(cnt)); memset(bitmask, 0, sizeof(bitmask)); memset(dp, 0, sizeof(dp)); // get prime number for(int i=2; i<71; i++) { bool flag = 1; for(int j=2; j*j<=i; j++) if(i%j == 0) flag = 0; if(flag) prim.push_back(i); } // get bitmask for each i for(int i=2; i<71; i++) { int t = i; for(int j=0; j<(int)prim.size(); j++) { int num = 0, div = prim[j]; while(t%div == 0) { t /= div; num ++; } if(num&1) bitmask[i] += 1<<j; } }}int main() { //freopen("test.txt","r",stdin); init(); int n; scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d",&a[i]); cnt[a[i]] ++; } // solve int sz = (int)prim.size(); dp[0][0] = 1; for(int i=1; i<71; i++) { int mask = bitmask[i], cur = i&1, last = !cur; for(int j=0; j<(1<<sz); j++) { if(cnt[i] == 0) dp[cur][j] = dp[last][j]; else { dp[cur][j] = (dp[cur][j] + dp[last][j]*pw[cnt[i]-1]%mod) % mod; dp[cur][j^mask] = (dp[cur][j^mask] + dp[last][j]*pw[cnt[i]-1]%mod) % mod; } } for(int j=0; j<(1<<sz); j++) dp[last][j] = 0; //printf("%d : %I64d\n",i,dp[i][0]); } printf("%I64d\n",(dp[0][0]-1+mod)%mod); return 0;}
阅读全文
0 0
- Codeforces 895C(状压)
- Codeforces 895C
- codeforces 895C
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- CODEFORCES 265C CODEFORCES, 265C
- codeforces #78 div2 C
- Codeforces 117C Cycle
- CodeForces 209C
- CodeForces 156C Cipher
- codeforces 148 div2 C
- codeforces 242C
- Codeforces-234C Weather
- codeforces 106C Buns
- codeforces 158C
- Codeforces 243C
- 在Eclipse中JavaEE项目误删Servers后的恢复办法
- git无法pull仓库
- swing图形设计连接mysql数据库的步骤
- Python3
- python中的排序
- codeforces 895C
- spring事务
- 题解~~~~
- PHP之SPHINX的使用(全文搜索引擎)
- 设计模式之命令模式
- GYM
- 11
- ZCMU1620
- Access denied for user 'root'@'windows10.microdone.cn' (using password: YES)