Vasya and Shifts CodeForces - 832E (高斯消元)
大意: 给定$4n$个$m$位的五进制数, $q$个询问, 每个询问给出一个$m$位的五进制数$b$, 求有多少种选数方案可以使五进制异或和为$b$.
高斯消元入门题
每次询问相当于就是给定了$m$个式子组成的模$5$的方程组, 求解的个数
如果消元后询问某一位非零, 但是对应系数矩阵全零, 那么无解
否则解的个数是$5^{n-r}$
$q$组询问的话, 就增广$q$列, 同时解$q$个方程组即可.
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 510;
int n, m, q, A[N][2*N], in[N];
char s[N]; int main() {
REP(i,0,4) in[i]=i*i*i%5;
scanf("%d%d", &n, &m);
REP(i,1,n) {
scanf("%s",s+1);
REP(j,1,m) A[j][i]=s[j]-'a';
}
scanf("%d", &q);
REP(i,1,q) {
scanf("%s",s+1);
REP(j,1,m) A[j][i+n]=s[j]-'a';
}
int r = 0;
REP(i,1,n) {
int p = r;
while (!A[p][i]&&p<=m) ++p;
if (p>m) continue;
if (p!=r) REP(j,1,n+q) swap(A[p][j],A[r][j]);
REP(j,1,m) if (j!=r&&A[j][i]) {
int t = A[j][i]*in[A[r][i]]%5;
REP(k,i,n+q) A[j][k]=(A[j][k]-t*A[r][k]+25)%5;
}
++r;
}
REP(i,1,q) {
int ans = qpow(5,n-r);
REP(j,1,m) if (A[j][i+n]) {
int ok = 0;
REP(k,1,n) if (A[j][k]) ok = 1;
if (!ok) ans = 0;
}
printf("%d\n",ans);
}
}
Vasya and Shifts CodeForces - 832E (高斯消元)的更多相关文章
- Codeforces 1163E 高斯消元 + dfs
题意:给你一个集合,让你构造一个长度尽量长的排列,使得排列中任意相邻两个位置的数XOR后是集合中的数. 思路:我们考虑枚举i, 然后判断集合中所有小于1 << i的数是否可以构成一组异或空 ...
- Codeforces 832E Vasya and Shifts - 高斯消元
题目传送门 快速的传送门I 快速的传送门II 题目大意 (题意比较复杂,请自行阅读原题) 可以将原题的字母都看成它们的在字符表中的下标,这样问题就变成给定$n$个$m$维向量$\vec{a_{1}}, ...
- Codeforces Gym10008E Harmonious Matrices(高斯消元)
[题目链接] http://codeforces.com/gym/100008/ [题目大意] 给出 一个n*m的矩阵,要求用0和1填满,使得每个位置和周围四格相加为偶数,要求1的数目尽量多. [题解 ...
- Codeforces Round #114 (Div. 1) E. Wizards and Bets 高斯消元
E. Wizards and Bets 题目连接: http://www.codeforces.com/contest/167/problem/E Description In some countr ...
- CodeForces 24D Broken robot(期望+高斯消元)
CodeForces 24D Broken robot 大致题意:你有一个n行m列的矩形板,有一个机器人在开始在第i行第j列,它每一步会随机从可以选择的方案里任选一个(向下走一格,向左走一格,向右走一 ...
- Educational Codeforces Round 63 (Rated for Div. 2) E 带模高斯消元
https://codeforces.com/contest/1155/problem/E 题意 \(f(x)=a_0+a_1x+a_2x^2+...+a_kx^k,k \leq 10,0 \leq ...
- Codeforces 446D - DZY Loves Games(高斯消元+期望 DP+矩阵快速幂)
Codeforces 题目传送门 & 洛谷题目传送门 神仙题,%%% 首先考虑所有格子都是陷阱格的情况,那显然就是一个矩阵快速幂,具体来说,设 \(f_{i,j}\) 表示走了 \(i\) 步 ...
- Codeforces.24D.Broken robot(期望DP 高斯消元)
题目链接 可能这儿的会更易懂一些(表示不想再多写了). 令\(f[i][j]\)表示从\((i,j)\)到达最后一行的期望步数.那么有\(f[n][j]=0\). 若\(m=1\),答案是\(2(n- ...
- Codeforces.472F.Design Tutorial: Change the Goal(构造 线性基 高斯消元)
题目链接 \(Description\) 给定两个长为\(n\)的数组\(x_i,y_i\).每次你可以选定\(i,j\),令\(x_i=x_i\ \mathbb{xor}\ x_j\)(\(i,j\ ...
随机推荐
- sublime text 3插件改造之添加从模版新增文件到指定目录
简介:以前使用ST2里面的Sublime NFFT插件比较顺手,最近安装了ST3,但是Sublime NFFT插件不支持ST3,就下载了SublimeTmpl从模版新建文件插件.在使用时,习惯在侧边栏 ...
- 洛谷P4343 [SHOI2015]自动刷题机
题目 易得该题目中的\(n\)和\(k\)具有单调性,满足二分的性质,因此该题目而已用二分来枚举\(n\),然后对于每个\(n\)模拟出它所对应的\(k\),然后注意注意代码细节,并且当当前\(k\) ...
- Android入门教程(一)
Android是什么? Android是基于Linux开发性内核的操作系统,该平台由操作系统,中间件,用户界面和应用软件组成.Android的基本信息:软件类型,APK,发行商:Google,最早版本 ...
- h5的复制功能的使用,Clipboard.js的使用,主要是在app里面使用
app中使用,框架用的是vue.js 1.显示要下载这个Clipboard.js插件 package-lock.json里面 "clipboard-polyfill": { &qu ...
- element ui 中的时间选择器怎么设置默认值/el-date-picker区间选择器怎么这是默认值
template代码 <el-date-picker value-format="yyyy-MM-dd" v-model="search.date" ty ...
- pytorch中tensor数据和numpy数据转换中注意的一个问题
转载自:(pytorch中tensor数据和numpy数据转换中注意的一个问题)[https://blog.csdn.net/nihate/article/details/82791277] 在pyt ...
- epoll 或者 kqueue 的原理是什么?
来自知乎:http://www.zhihu.com/question/20122137 epoll 或者 kqueue 的原理是什么? 为什么epoll和kqueue可以用基于事件的方式,单线程的实现 ...
- ERROR: relation "pg_buffercache" does not exist
创建pg_buffercache后,查询时报错: postgres=# create extension pg_buffercache; postgres=# select * from pg_buf ...
- Spring Boot源码中模块详解
Spring Boot源码中模块详解 一.源码 spring boot2.1版本源码地址:https://github.com/spring-projects/spring-boot/tree/2.1 ...
- js控制input框只能输入数字和一位小数点和小数点后面两位小数
<script language="JavaScript" type="text/javascript"> function clearNoNum( ...