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) 然后就是矩阵快速幂,然而我并不能 ...
随机推荐
- RSA_JS_PHP加密解密
root@DESKTOP-I4OIMJC /cygdrive/e/html/RSA_JS_PHP/openssl/bin # ./openssl.exe OpenSSL> genrsa -out ...
- Jmeter如何监控服务器性能
1.jmeter只需要安装一些插件 ,就可以像loadrunner一样监控服务器CPU.内存等性能参数 1.下载需要的jmeter插件 如图上面两个是jmeter插件,可以再下面的链接中下载 ...
- [BZOJ][CQOI2014]数三角形
Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形. 注意三角形的三点不能共线. Input 输入一行,包含两个空格分隔的正整数m和 ...
- 浪潮openStack云
- addin1
Mono.addin是一个插件框架,更多信息请访问 http://monoaddins.codeplex.com/
- minio test
docker pull minio/minio docker run --name=minio -d -p 9001:9000 minio/minio server /data https://do ...
- pyinstaller打包后运行提示找不到模块
截止到2017年9月20号,pyinstaller只支持到python3.5,如果需要支持到3.6,需要自己在github上下载pyinstaller的开发版. 在打包时候,并没有提示错误,可以顺利打 ...
- 基于Linux服务器的性能分析与优化
作为一名Linux系统管理员,最主要的工作是优化系统配置,使应用在系统上以最优的状态运行,但硬件问题.软件问题.网络环境等的复杂性和多变性,导致了对系统的优化变得异常复杂,如何定位性能问题出在哪个方面 ...
- OceanBase
OceanBase 编辑 本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧! OceanBase是一个支持海量数据的高性能分布式数据库系统,实现了 数千亿条记录.数百TB数据上的 ...
- 670. Maximum Swap 允许交换一个数 求最大值
[抄题]: Given a non-negative integer, you could swap two digits at most once to get the maximum valued ...