Codeforces 895.C Square Subsets】的更多相关文章

C. Square Subsets time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Petya was late for the lesson too. The teacher gave him an additional task. For some array a Petya should find the number…
题目链接 Codeforces Round #448 C. Square Subsets 题解 质因数 *质因数 = 平方数,问题转化成求异或方程组解的个数 求出答案就是\(2^{自由元-1}\) ,高消求一下矩阵的秩,完了 或者 由于数很小, 我们只需要对于每个数的质因数装压 对这组数求线性基,n - 线性基中的数就是自由元个数 代码 #include<bits/stdc++.h> using namespace std; inline int read() { int x = 0,f =…
895C - Square Subsets 思路:状压dp. 每个数最大到70,1到70有19个质数,给这19个质数标号,与状态中的每一位对应. 状压:一个数含有这个质因子奇数个,那么他状态的这一位是1,一个数含有这个这个质因子偶数个,那么状态的这一位是0. 那么如果一个数是平方数,那么这个数的状态每一位都是0,即状态为0. 状态转移见代码. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #defin…
题目链接  Square Subsets 这是白书原题啊 先考虑状压DP的做法 $2$到$70$总共$19$个质数,所以考虑状态压缩. 因为数据范围是$70$,那么我们统计出$2$到$70$的每个数的个数然后从$2$考虑到$70$. 设$dp[x][mask]$为考虑到$x$这个数的时候,$x$这个数和之前的所有数中,选出某些数,他们的乘积分解质因数,所有的指数对$2$取模之后, 状态为$mask$的方案数. 然后就可以转移了……这个状压DP花了我好几个小时……真是弱啊 哦对最后还要特判$1$的…
Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum pos…
CF895C: Square Subsets && [BZOJ2844]albus就是要第一个出场 这两道题很类似,都是线性基的计数问题,解题的核心思想也一样. CF895C Square Subsets 题目链接 题意 给定\(n\)个数,求多少种选数方案使得选出来的数乘积为完全平方数.\(n\leq 100000,a_i\leq70\). 完全平方数的本质就是每个质因子的次数为偶数. 所以我们将每一个数唯一分解,然后记录每个质因子的奇偶状态,就得到了一个个01串.问题就变成了有多少个集…
题目链接:http://codeforces.com/problemset/problem/895/C 题意: 给你n个数a[i].(n <= 10^5, 1 <= a[i] <= 70) 问你有多少非空子集s,使得 ∏(s[i])为完全平方数. 题解: 由于a[i] <= 70,而70以内的质数只有19个,显然可以状压. 由于一个数是完全平方数的条件是:它的每种质因子的指数为偶数 所以先处理出对于每个a[i],它的所有质因子指数的奇偶性f[i]. 对于f[i]的每一位,0表示它的…
题意: 给了n个数,要求有几个子集使子集中元素的和为一个数的平方. 题解: 因为每个数都可以分解为质数的乘积,所有的数都小于70,所以在小于70的数中一共只有19个质数.可以使用状压DP,每一位上0表示这个质数的个数为偶数个,1表示为奇数个.这样的话,如果某个数为一个数的平方的话,那么每个质数个数都是偶数,用0可以表示.从1-70开始状压DP,先存下每个数出现多少次,然后dp转移,dp转移时分别计算某个数出现奇数次还是偶数次的方案数. 这里有一个公式:C(n,0)+C(n,2)+--=C(n,1…
可以用状压dp,也可以用线型基,但是状压dp没看台懂... 线型基的重要性质 性质一:最高位1的位置互不相同 性质二:任意一个可以用这些向量组合出的向量x,组合方式唯一 性质三:线性基的任意一个子集异或和不为0. 详细见:线型基介绍 题意:给一个数组,找相乘起来是完全平方数的所有组数 解法:先打70的素数表,对每一个数的素数因子个数%2之后进行压位,为什么要这样做呢,是因为,相乘之后如果是素数那么一定能分解成偶数个素数因子相乘,那么就可以转化成求亦或起来是0的组数,用线型基处理,对于不在线型基中…
A - Theatre Square Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 1A Description Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the…
题目链接:http://codeforces.com/problemset/problem/710/C 题目大意:输入一个奇数n,则生成n*n矩阵,要求矩阵的行.列还有斜着,所有元素之和为奇数. 解题思路:要符合行.列还有斜着,所有元素之和为奇数,则保证行.列或者斜着,有奇数个奇数 和 偶数个偶数即可. 32 4 8 5 2 4 6 8 10 3 5 7 12 9 11 13 15 17 14 19 21 23 16 18 20 22 24 7 2 4 6 8 10 12 14 16 3 5 7…
B. Petya and Square time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Petya loves playing with squares. Mum bought him a square 2n × 2n in size. Petya marked a cell inside the square…
http://codeforces.com/problemset/problem/300/D 题意:每一次操作可以选一个正方形,令边长为n,如果n为奇数那么可以从中间画一个十字,分成4个大小相等的边长为(n-1)/2的正方形.给一个正方形,求操作k次后能得到的不同图案的个数 思路:令f(s,k)表示边长为s的正方形操作k次后的答案总数,则f(s,k)=∑f(s/2,k1)*f(s/2,k2)*f(s/2,k3)*f(s/2,k4),其中s为奇数,k1+k2+k3+k4=k-1,令g(s,k)=Σ…
E. Eyes Closed time limit per test 2.5 seconds memory limit per test 256 megabytes input standard input output standard output Vasya and Petya were tired of studying so they decided to play a game. Before the game begins Vasya looks at array a consis…
D. String Mark time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output At the Byteland State University marks are strings of the same length. Mark x is considered better than y if string y is lexi…
B. XK Segments time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher sug…
题目大意:给一个集合$S$($1\leq S_i\leq 70$),选择一个非空子集,使它们的乘积等于某个整数的平方的方法的数量. 求方案数,若两种方法选择的元素的索引不同,则认为是不同的方法. 题解:$70$以内的质数只有$19$个,考虑状压$DP$,$f_{i,j}$表示这个数为$i$,若$j$二进制下的第$k$位为$1$,表示它含第$k$个质数奇数个,转移显然 卡点:无 C++ Code: #include <cstdio> #include <cstring> #defin…
洛谷传送门 不知道线性基是什么东西的可以看看蒟蒻的总结 题意: 给你n个数,每个数<=70,问有多少个集合,满足集合中所有数相乘是个完全平方数(空集除外) 题解: 完全看不出这玩意儿和线性基有什么关系……我可能太菜了…… 首先,一个完全平方数分解质因数之后每个质因子都出现偶数次 又因为小于等于$70$的质数总共18个,可以用18位的二进制表示,0表示偶数次,1表示奇数次 那么两个数相乘就是每一个质因子表示的位的异或 那么就是求有多少种方法相乘得0 首先求出原数组的线性基,设$cnt$表示线性基内…
A. Pizza Separation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order…
题目大意:给你一个序列,你可以在序列中任选一个子序列,求子序列每一项的积是一个平方数的方案数. 1<=a[i]<=70 因为任何一个大于2的数都可以表示成几个质数的幂的乘积 所以我们预处理70以内的质数,把它作为二进制状压的状态,每个在序列中出现数Hash一下,组合数推一下 所以把奇次幂的状态表示为1,偶次幂的状态就是0,比如6就是11,42就是1011 而平方数的每个质因子的指数都是偶数,所以最终结果的状态就是0000000... 转移的过程,两个数的乘积,就是这两个数的质因子二进制的状态的…
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个序列 x = {x1, x2, ..., xn},已知 xi 是一个在 [li, ri] 内的随机整数. 令 B(x) 表示将序列 x 划分成若干连续的段,使每个段内所有数相同的最小划分数. 求 (B(x))^2 的期望 E((B(x))^2). Input 第一行包含一个整数 n (1≤n≤2⋅10^5))表示序列长度. 第二行包含 n 个整数 l1,…
线性基的题- 考虑平方数只和拆解质因子的个数的奇偶性有关系 比如说你 \(4\) 和 \(16\) 的贡献都是一样的.因为 \(4 = 2^2 , 16 = 2^4\) \(2\) 和 \(4\) 奇偶性相同 然后考虑如何线性基,不难想到,二进制可以表示奇偶性, 所以异或和每一位是0的时候就是一个平方数了. 我们考虑把 线性基的元素设为 \(|S|\) 个 那么你手头只剩下 \(n-|S|\) 个数字还可以被线性基表示的. 如果可以表示,那么说明了这些 \(2^{n-|S|}-1\) 个子集异或…
被B的0的情况从头卡到尾.导致没看C,心情炸裂又掉分了. A. Pizza Separation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the…
Pizza Serparation #include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector> #include<algorithm> #include<iostream> #include<map> #include<queue> using std::vector; using std::queue; using std:…
有的DP题,某一部分的状态只有两种,选或不选. 开数组记录,代价太大,转移不方便. 状态压缩意为,用 “0/1“ 表示 “选/不选“ . 把状态表示为二进制整数. There are 10 kinds of people in the world, who knows binary and who doesn't. 用位运算判断条件并转移状态. hdu 6149 Valley Numer II 题目传送门 用f[i][j]表示选到前i个点,状态为j的答案. 枚举其他两个高点. 转移之前判断之前是…
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd. 输入 The only line contains odd integer n (1 ≤ n ≤ 49). 输出 Print n lines…
题目链接:Codeforces 417E Square Table 题目大意:给出n和m.要求给出一个矩阵,要求每一列每一行的元素的平方总和是一个平方数. 解题思路:构造.依照 a a a b a a a b a a a b c c c d 的方式取构造,然后a,b,c,d的值用随机生成数去枚举,只是我认为用暴力也是能够的. #include <cstdio> #include <cstring> #include <cmath> #include <cstdli…
C. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) an…
题目连接:Codeforces 432E Square Tiling 题目大意:给出一个n∗m的矩阵,要求对该矩阵进行上色,用大写字母,可是每次上色的区域必须是正方形,不求相邻的上色区域不能有同样的颜色.求字典序最小的方案(字典序比較.从左至右.从上到下) 解题思路:用贪心的思想去构造矩阵,由于字典序的优先级为左至右,以及上到下,所以我们每次对于一个未上色点x,y.考虑最少要放到的长度p就可以. #include <cstdio> #include <cstring> #inclu…
题目网址:http://codeforces.com/contest/828/problem/B 题目: Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint mini…