codeforces 691E Xor-sequences 矩阵快速幂
思路:刚开始 n个元素,a[i][j]代表以i开头,j结尾的二元组符合条件的有多少
这是等于长度为2的数量 长度为3的数量为a*a,所以长度为n的数量是a^(k-1)
然后就是矩阵快速幂,然而我并不能发现这道题是矩阵快速幂,没办法,太弱了
注:这个模板是从Q神的AC代码里扒下来的,仰慕Q神
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 1e2+;
const LL mod = 1e9+; LL a[],n,k;
struct Matrix{
LL a[N][N];
Matrix(){
memset(a,,sizeof(a));
}
void init(){
for(int i=;i<=n;++i)a[i][i]=;
}
Matrix operator *(const Matrix &rhs)const{
Matrix ret;
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
for(int k=;k<=n;++k)
ret.a[i][j]=(ret.a[i][j]+a[i][k]*rhs.a[k][j]%mod)%mod;
return ret;
}
Matrix operator ^(LL mi)const{
Matrix tmp=(*this),ret;
ret.init();
while(mi){
if(mi&)ret=ret*tmp;
tmp=tmp*tmp;
mi>>=;
}
return ret;
}
}; int main(){
scanf("%I64d%I64d",&n,&k);
for(int i=;i<=n;++i)
scanf("%I64d",&a[i]);
Matrix cur;
for(int i=;i<=n;++i){
for(int j=;j<=n;++j)
if(__builtin_popcountll(a[i]^a[j])%==)
++cur.a[i][j];
}
cur=cur^(k-);
LL ret=;
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
ret=(ret+cur.a[i][j])%mod;
printf("%I64d\n",ret);
return ;
}
codeforces 691E Xor-sequences 矩阵快速幂的更多相关文章
- Codeforces 691E题解 DP+矩阵快速幂
题面 传送门:http://codeforces.com/problemset/problem/691/E E. Xor-sequences time limit per test3 seconds ...
- CodeForces - 691E Xor-sequences 【矩阵快速幂】
题目链接 http://codeforces.com/problemset/problem/691/E 题意 给出一个长度为n的序列,从其中选择k个数 组成长度为k的序列,因为(k 有可能 > ...
- Codeforces 691E Xor-sequences(矩阵快速幂)
You are given n integers a1, a2, ..., an. A sequence of integers x1, x2, ..., xk is called a & ...
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)
题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. /* | 1, -1 | | fn | | 1, 0 | | f ...
- Codeforces 450B div.2 Jzzhu and Sequences 矩阵快速幂or规律
Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...
- codeforces 450B B. Jzzhu and Sequences(矩阵快速幂)
题目链接: B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces 954 dijsktra 离散化矩阵快速幂DP 前缀和二分check
A B C D 给你一个联通图 给定S,T 要求你加一条边使得ST的最短距离不会减少 问你有多少种方法 因为N<=1000 所以N^2枚举边数 迪杰斯特拉两次 求出Sdis 和 Tdis 如果d ...
- Xor-sequences CodeForces - 691E || 矩阵快速幂
Xor-sequences CodeForces - 691E 题意:在有n个数的数列中选k个数(可以重复选,可以不按顺序)形成一个数列,使得任意相邻两个数异或的结果转换成二进制后其中1的个数是三的倍 ...
- codeforces 691E 矩阵快速幂+dp
传送门:https://codeforces.com/contest/691/problem/E 题意:给定长度为n的序列,从序列中选择k个数(可以重复选择),使得得到的排列满足xi与xi+1异或的二 ...
随机推荐
- hdu 1352 I Conduit!
计算几何,主要是排序问题,其他都很好做…… ;}
- Project Euler 96:Su Doku 数独
Su Doku Su Doku (Japanese meaning number place) is the name given to a popular puzzle concept. Its o ...
- Project Euler 87 :Prime power triples 素数幂三元组
Prime power triples The smallest number expressible as the sum of a prime square, prime cube, and pr ...
- 【mysql的编程专题①】流程控制与其他语法
流程控制与内置函数,一般用在select的field字段上,或者用在函数,存储过程,触发器中; 如果用在select上就会随着query出来的row来隐式迭代; 注释与语句结束符 语句结束符 默认有两 ...
- HttpServletRequestWrapper的使用
老大给了一个很实际的需求:有段程序,使用Http的方式与合作商交互,而且是明文传输数据.我方的代码已经打包放在服务器上运行了很长时间,这时合作商突然要求修改数据传输的方式,要求加密后再传输,而我方的原 ...
- erp中三大订单CO、PO、MO各是代表什么?
ERP即 企业资源计划 (Enterprise Resource Planning),由美国 Gartner Group 公司于1990年提出. ERP系统是指建立在信息技术基础上,以系统化的管理思想 ...
- Android 标题栏封装
自定义命名空间与xml文件:
- Java对象的序列化(Object Serialization)
先定义两个简单的类: package comm; import java.io.Serializable; import java.util.Date; import java.util.Gregor ...
- MyEclipse +Servlet 乱码
用MyEclipse 新建了Web Project,然后建立了一个Servlet,在doGet方法中谢了简单的一句欢迎语句,本来以为平平常常的事情,但是却出错了,乱码问题,在网上找了一些帖子,说是设置 ...
- BZOJ 2339 卡农(组合数学)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2339 题意: 思路: i64 Pow(i64 a,i64 b,i64 mod){ ...