300个最大质因数小于2000的数,选若干个它们的乘积为完全平方数有多少种方案. 合法方案的每个数的质因数的个数的奇偶值异或起来为0. 比如12=2^2*3,对应的奇偶值为01(2的个数是偶数为0,3的个数是奇数为1),3的对应奇偶值为01,于是12*3是完全平方数. 然后异或方程组就是: a11x1+a12x2+...+a1nxn=0 a21x1+a22x2+...+a2nxn=0 ... an1x1+an2x2+...+annxn=0 aij:第i个质数(2000内有303个质数)在第j个数…
ccpc网赛卡住的一道题 蓝书上的原题 但是当时没看过蓝书 今天又找出来看看 其实也不是特别懂 但比以前是了解了一点了 主要还是要想到构造异或方程组 异或方程组的消元只需要xor就好搞了 数学真的是硬伤啊…… (链接:蓝书161页详细讲解 我也在看…… #include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include…
基本思路.首先构造一个n*(m+1)的矩阵,同时标记一个行数row,row从零开始,然后找出每一列第一个非零的数,和第row行互换, 然后对row到n行,异或运算.最终的结果为2^(m-row) #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int array[55][55],n,m,h[55][55]; int main() { int i,j,k,t,a,q…
题目大意:给出n个数字a[],将a[]分解为质因子(保证分解所得的质因子不大于2000),任选一个或多个质因子,使其乘积为完全平方数.求其方法数. 学长学姐们比赛时做的,当时我一脸懵逼的不会搞……所以第二天上午花了一上午学习了一下线性代数. 题目思路: 任选一个或多个质因子,起乘积为完全数m,因为组成它的均为素数,假设组成m的素数的种类为n,那么这n类素数中每类素数的个数应为偶数. 可设:a[i][j]=0代表第i种素数可在a[j]中分离出的个数为偶数,a[i][j]=1代表第i种素数可在a[j…
题目链接 题意:给定一个4*4的矩阵,有两种颜色,每次反转一个颜色会反转他自身以及上下左右的颜色,问把他们全变成一种颜色的最少步数. 题解:4*4的矩阵打表可知一共有四个自由变元,枚举变元求最小解即可. 代码: #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <queue> #…
题目链接 中文题,高斯消元模板题. #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <queue> #include <vector> #include <map> #include <ctime> using namespace std;…
Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8481   Accepted: 5479 Description In an extended version of the game Lights Out, is a puzzle with 5 rows of 6 buttons each (the actual puzzle has 5 rows of 5 buttons each). Each button has…
状压,时间空间都不行,如果每次搜索一半就可以省下很多空间,用map记下每种状态的答案,最后再把两次的答案合并 然而正解是高斯消元解异或方程组,最后搜索自由元 #include<iostream> #include<cstdio> #include<cstring> #include<map> #define ll long long using namespace std; ; ; ,fl; ll f[maxn]; map<ll,int>mx;/…
题目链接:http://poj.org/problem?id=3185 题意:20盏灯排成一排.操作第i盏灯的时候,i-1和i+1盏灯的状态均会改变.给定初始状态,问最少操作多少盏灯使得所有灯的状态最后均为0. 思路:高斯消元,记录变元个数,枚举变元. int a[N][N],ans[N]; vector<int> b; int Gauss() { b.clear(); int i,j=1,k,t; for(i=1;i<=20;i++) { for(k=j;k<=20;k++) i…
http://poj.org/problem?id=1681 题意:有一块只有黄白颜色的n*n的板子,每次刷一块格子时,上下左右都会改变颜色,求最少刷几次可以使得全部变成黄色. 思路: 这道题目也就是要处理自由变元,如果自由变元为0,那么刷法是唯一的,如果有多个自由变元,那么可以有多种刷法,需要枚举处理. 借鉴了kuangbin大神的高斯消元模板,写得真的是好. #include<iostream> #include<algorithm> #include<cstring&g…