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.

Input

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).

Output

Print the only integer c — the number of "xor-sequences" of length k modulo 109 + 7.

Examples
input
5 2
15 1 2 4 8
output
13
input
5 1
15 1 2 4 8
output
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(矩阵快速幂)的更多相关文章

  1. Codeforces 691E题解 DP+矩阵快速幂

    题面 传送门:http://codeforces.com/problemset/problem/691/E E. Xor-sequences time limit per test3 seconds ...

  2. CodeForces - 691E Xor-sequences 【矩阵快速幂】

    题目链接 http://codeforces.com/problemset/problem/691/E 题意 给出一个长度为n的序列,从其中选择k个数 组成长度为k的序列,因为(k 有可能 > ...

  3. Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)

    题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. /* | 1, -1 | | fn | | 1, 0 | | f ...

  4. 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 ...

  5. codeforces 450B B. Jzzhu and Sequences(矩阵快速幂)

    题目链接: B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input ...

  6. Codeforces 954 dijsktra 离散化矩阵快速幂DP 前缀和二分check

    A B C D 给你一个联通图 给定S,T 要求你加一条边使得ST的最短距离不会减少 问你有多少种方法 因为N<=1000 所以N^2枚举边数 迪杰斯特拉两次 求出Sdis 和 Tdis 如果d ...

  7. Xor-sequences CodeForces - 691E || 矩阵快速幂

    Xor-sequences CodeForces - 691E 题意:在有n个数的数列中选k个数(可以重复选,可以不按顺序)形成一个数列,使得任意相邻两个数异或的结果转换成二进制后其中1的个数是三的倍 ...

  8. codeforces 691E 矩阵快速幂+dp

    传送门:https://codeforces.com/contest/691/problem/E 题意:给定长度为n的序列,从序列中选择k个数(可以重复选择),使得得到的排列满足xi与xi+1异或的二 ...

  9. codeforces 691E Xor-sequences 矩阵快速幂

    思路:刚开始 n个元素,a[i][j]代表以i开头,j结尾的二元组符合条件的有多少 这是等于长度为2的数量 长度为3的数量为a*a,所以长度为n的数量是a^(k-1) 然后就是矩阵快速幂,然而我并不能 ...

随机推荐

  1. @RestController的方法中 路径参数带.(点号)配置

    如下面这种//http://localhost:8080/api/v1/user/info/email/test@163.com @RequestMapping(value = "/info ...

  2. sql语句中避免使用mysql函数,提升mysql处理能力。

    如下sql中不要用mysql内置函数now()等,这样第一可以提高sql执行效率,第二统一程序层处理sql中时间参数,避免因服务器时间差导致问题产生. 使用PDO预处理,第一可以提高sql效率,第二可 ...

  3. .net core 下的Area注册

    app.UseMvc(routes => { routes.MapAreaRoute( name: "AreaRoute", areaName: "Admin&qu ...

  4. shell编程——内部变量

    常用的内部变量有:echo, eval, exec, export, readonly, read, shift, wait, exit 和 点(.) echo:将变量名指定的变量显示到标准输出 [r ...

  5. Linux下的service命令和chkconfig命令的原理

    CentOS下的service命令和chkconfig命令的原理 1.service命令的原理 service命令用来对服务进行启动和关闭,比如service mysqld start可以启动mysq ...

  6. Hash表算法详解

    Hash表定义 散列表(Hash table,也叫哈希表),是根据关键字值(Key value)直接进行访问的数据结构.也就是说,它通过把关键字(关键字通过Hash算法生成)映射到表中一个位置来访问记 ...

  7. 前端开发之CSS篇三

    主要内容:  一.CSS布局之浮动     二.清除浮动带来的问题     三.margin塌陷问题和水平居中     四.善用父级的的padding取代子级的margin     五.文本属性和字体 ...

  8. 运动函数封装(js)

    // 运动函数 function starMove(obj,json,fnEnd){ clearInterval(obj.timer); obj.timer  = setInterval(functi ...

  9. Linux实战教学笔记44:NoSQL数据库开篇之应用指南

    第1章 NoSQL数据库 1.1 NoSQL概述 自关系型数据库诞生40年以来,从理论产生发展到现实产品,例如:大家最常见的MySQL和Oracle,逐渐在数据库领域里上升到了霸主地位,形成每年高达数 ...

  10. Perl 变量:哈希变量

    Perl 哈希变量哈希是 key/value 对的集合.Perl中哈希变量以百分号 (%) 标记开始.访问哈希元素格式:${key}. 1.创建哈希创建哈希可以通过以下两种方式: 1.为每个 key ...