Codeforces 691E Xor-sequences(矩阵快速幂)
You are given n integers a1, a2, ..., an.
A sequence of integers x1, x2, ..., xk is called a "xor-sequence" if for every 1 ≤ i ≤ k - 1 the number of ones in the binary representation of the number xi
xi + 1's is a multiple of 3 and
for all 1 ≤ i ≤ k. The symbol
is used for the binary exclusive or operation.
How many "xor-sequences" of length k exist? Output the answer modulo 109 + 7.
Note if a = [1, 1] and k = 1 then the answer is 2, because you should consider the ones from a as different.
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1018) — the number of given integers and the length of the "xor-sequences".
The second line contains n integers ai (0 ≤ ai ≤ 1018).
Print the only integer c — the number of "xor-sequences" of length k modulo 109 + 7.
5 2
15 1 2 4 8
13
5 1
15 1 2 4 8
5 题意:给出n个数,让你取出k个构成一个新串,使这些串中每相邻两个数异或起来得到的数二进制表达下一的个数是三的倍数,求这些串的个数 题解:显然可以暴力预处理出构成长度为2的方法,然后用矩阵快速幂跑一下就可以了 代码如下:
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mod 1000000007
#define int long long
using namespace std; struct matrix
{
int m[][];
void init()
{
for(int i=;i<=;i++)
{
m[i][i]=;
}
}
void clr()
{
memset(m,,sizeof(m));
}
}; int n,m[];
int k; matrix mul(matrix a,matrix b)
{
matrix ans;
ans.clr();
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
for(int k=;k<=n;k++)
{
ans.m[i][j]+=a.m[i][k]*b.m[k][j];
ans.m[i][j]%=mod;
}
}
}
return ans;
} matrix kasumi(matrix a,int b)
{
matrix ans;
ans.clr();
ans.init();
while(b)
{
if(b&)
{
ans=mul(ans,a);
}
a=mul(a,a);
b>>=;
}
return ans;
} signed main()
{
scanf("%lld%lld",&n,&k);
for(int i=;i<=n;i++)
{
scanf("%lld",&m[i]);
}
matrix x;
x.clr();
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(__builtin_popcountll(m[i]^m[j])%==)
{
x.m[i][j]=;
}
}
}
x=kasumi(x,k-);
int ans=0ll;
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
ans+=x.m[i][j];
ans%=mod;
}
}
printf("%lld\n",ans);
}
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 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异或的二 ...
- codeforces 691E Xor-sequences 矩阵快速幂
思路:刚开始 n个元素,a[i][j]代表以i开头,j结尾的二元组符合条件的有多少 这是等于长度为2的数量 长度为3的数量为a*a,所以长度为n的数量是a^(k-1) 然后就是矩阵快速幂,然而我并不能 ...
随机推荐
- ubuntu下安装oracle java8
1.首先添加ppa $ sudo add-apt-repository ppa:webupd8team/java 2.然后更新系统 $ sudo apt-get update 3.最后开始安装 $ s ...
- <a>标签中的href="javascript:;"就是去掉a标签的默认行为
<a>标签中的href="javascript:;"是什么意思? 例子:<a href="javascript:;">我的大学</ ...
- Redis 主从同步配置
主从功能: 为了防止 Redis 磁盘损坏,导致数据丢失,Redis 提供了复制功能,将一个主数据库的数据自动同步到从数据库,防止数据丢失. 同时还可以配置一主多从来分担主压力,主只接受写的操作,将读 ...
- ios编译出错:UIButton.h' has been modified since the precompiled header UIKit.pcm' was built
今天编译遇到个问题:如下 fatal error: file '/Applications/Xcode 2.app/Contents/Developer/Platforms/iPhoneSimulat ...
- Linux下Spark框架配置(Python)
简述 Spark是UC Berkeley AMP lab所开源的类Hadoop MapReduce的通用并行框架,Spark,拥有Hadoop MapReduce所具有的优点:但不同于MapRedu ...
- Linux运维入门(二):网络基础知识梳理02
一,交换机的基本原理 1.1 数据链路层的功能 (1)数据链路层负责网络中相邻节点之间可靠的数据通信,并进行有效的流量控制. (2)数据链路层的作用包括数据链路的建立,维护与拆除,帧包装,帧传输,帧同 ...
- 压力测试工具--Siege
Siege是一款开源的压力测试工具,设计用于评估WEB应用在压力下的承受能力.可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行.s ...
- H5/
1.value: 2.selected="selected": 设置selected="selected"属性,则该选项就被默认选中. 下拉列表也可以进行多选操 ...
- 学习h5(开始)
webstorm 下载地址:http://www.sdifenzhou.com/6176.html webstorm注册码: 43B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QT ...
- ajax请求后台有时走有时不走
ajax请求后台有时走有时不走 ajax请求后台有时走有时不走,是因为没有将请求设置为同步方式,async:false,(默认为true即异步).如果不想使用缓存可以将cache:false,例如 ...