可以用状压dp,也可以用线型基,但是状压dp没看台懂。。。

线型基的重要性质

性质一:最高位1的位置互不相同

性质二:任意一个可以用这些向量组合出的向量x,组合方式唯一

性质三:线性基的任意一个子集异或和不为0.

详细见:线型基介绍

题意:给一个数组,找相乘起来是完全平方数的所有组数

解法:先打70的素数表,对每一个数的素数因子个数%2之后进行压位,为什么要这样做呢,是因为,相乘之后如果是素数那么一定能分解成偶数个素数因子相乘,那么就可以转化成求亦或起来是0的组数,用线型基处理,对于不在线型基中的元素,那么它亦或线型基中某些数一定能变成0,那么就是找线型基的个数然后枚举所有可能的情况,就是2^t(t是不在线型基中的元素个数),最后排除一个也不取的情况

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pii pair<int,int> using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; bool isprime[];
int prime[],cnt;
void getprime()
{
cnt=;
for(int i=;i<=;i++)
{
if(!isprime[i])
{
prime[cnt++]=i;
for(int j=*i;j<=;j+=i)
isprime[j]=;
}
}
}
int main()
{
getprime();
int n;
scanf("%d",&n);
vector<int>base;
int k=;
for(int i=;i<=n;i++)
{
int x;
scanf("%d",&x);
int te=;
for(int j=;j<cnt;j++)
{
while(x%prime[j]==)
{
x/=prime[j];
te^=(<<j);
}
}
for(int j=;j<base.size();j++)
te=min(te,te^base[j]);
if(te)base.pb(te);
else k++;
}
ll ans=;
for(int i=;i<k;i++)
ans=ans*%mod;
printf("%lld\n",(ans-+mod)%mod);
return ;
}
/******************** ********************/

Codeforces Round #448 (Div. 2)C. Square Subsets的更多相关文章

  1. Codeforces Round #448(Div.2) Editorial ABC

    被B的0的情况从头卡到尾.导致没看C,心情炸裂又掉分了. A. Pizza Separation time limit per test 1 second memory limit per test ...

  2. Codeforces Round #448 (Div. 2) B

    题目描述有点小坑,ij其实是没有先后的 并且y并不一定存在于a中 判断y的个数和所给数组无关 对于2 - 7来说 中间满足%2==0的y一共有3个 2 4 6 这样 可以看出对于每个数字a 都能够二分 ...

  3. Codeforces Round #448 (Div. 2) B. XK Segments【二分搜索/排序/查找合法的数在哪些不同区间的区间数目】

    B. XK Segments time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. Codeforces Round #448 (Div. 2) A. Pizza Separation【前缀和/枚举/将圆(披萨)分为连续的两块使其差最小】

    A. Pizza Separation time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #448 C. Square Subsets

    题目链接 Codeforces Round #448 C. Square Subsets 题解 质因数 *质因数 = 平方数,问题转化成求异或方程组解的个数 求出答案就是\(2^{自由元-1}\) , ...

  6. Codeforces Round #372 (Div. 2)

    Codeforces Round #372 (Div. 2) C. Plus and Square Root 题意 一个游戏中,有一个数字\(x\),当前游戏等级为\(k\),有两种操作: '+'按钮 ...

  7. Codeforces Round #257 (Div. 1)A~C(DIV.2-C~E)题解

    今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and ...

  8. Codeforces Round #486 (Div. 3) D. Points and Powers of Two

    Codeforces Round #486 (Div. 3) D. Points and Powers of Two 题目连接: http://codeforces.com/group/T0ITBvo ...

  9. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

随机推荐

  1. IO流入门-第七章-BufferedReader

    BufferedReader基本用法和方法示例 /* 字节 BufferedInputStream BufferedOutputStream 字符 BufferedReader:带有缓冲区的字符输入流 ...

  2. mongoose学习

    #mongoose的使用详解# ##1.Scheme.model和Entity## Schema : 一种以文件形式存储的数据库模型骨架,不具备数据库的操作能力 Model : 由Schema发布生成 ...

  3. git 添加远程仓库后无法push

    push的时候提示fatal: refusing to merge unrelated histories   假如我们的源是origin,分支是master,那么我们 需要这样写git pull o ...

  4. git 从远程仓库指定分支clone代码到本地

    不指定分支 git clone + clone 地址 # 例如 git clone https://amc-msra.visualstudio.com/xxx/_xx/xxxxxx 指定分支 git ...

  5. 系列文章(二):从WLAN的安全威胁,解析电信诈骗的技术症结——By Me

    导读:互联网的无线接入已经成为大趋势,其中无线局域网(又称为WLAN,Wireless Local AreaNetwork)以其使用方便.组网灵活.可扩展性好.成本低等优点,成为互联网特别是移动互联网 ...

  6. R 入门笔记

    PS:初学R  为了查阅方便 借鉴的网友的博客和自己的总结记录一下 http://blog.csdn.net/jack237/article/details/8210598 命令简介 R对大小写是敏感 ...

  7. python学习之路-第八天-文件IO、储存器模块

    文件IO.储存器模块 文件IO 代码示例: # -*- coding:utf-8 -*- #! /usr/bin/python # filename:using_file.py poem = '''\ ...

  8. 单文件快速体验使用react输出hello_world

    看了下react官方的hello world教程, 感觉对新手很不友好.codepen虽然好用, 但是封装太多东西, 看起来 太抽象. 还是喜欢像学习jQuery那样, 直接在单文件中引入必要的js文 ...

  9. Oracle SQL 外键测试

    测试SQL 创建SQL     t1为主表      t2为子表 create table t1(insert_date number,id int) create table t2(insert_d ...

  10. Python一些常用模块

    阅读目录 一: collections模块 二: time,datetime模块 三: random模块 四: os模块 五: sys模块 六: json,pickle 七: re正则模块 八:re模 ...