E. Xor-sequences
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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
  1. 5 2
    15 1 2 4 8
output
  1. 13
input
  1. 5 1
    15 1 2 4 8
output
  1. 5
    思路:很好的一道矩阵乘法题,需要建立起模型。先预处理出一个矩阵,第ij个表示a[i]异或a[j]是否能被3整除,然后再将矩阵计算k-1次幂,最后将矩阵中所有元素加起来。
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<cstring>
  7. #include<string>
  8. #include<vector>
  9. #include<map>
  10. #include<set>
  11. #include<queue>
  12. #define mo 1000000007
  13. using namespace std;
  14. struct Matrix
  15. {
  16. long long a[][];
  17. };
  18. long long n,k,a[];
  19. Matrix st,ans;
  20. Matrix mul(Matrix a,Matrix b)
  21. {
  22. Matrix c;
  23. int i,j,k;
  24. //<F5>a.a[1][1]=1;
  25. for (i=;i<=n;i++)
  26. for (j=;j<=n;j++)
  27. {
  28. c.a[i][j]=;
  29. for (k=;k<=n;k++)
  30. c.a[i][j]=(c.a[i][j]+(a.a[i][k]*b.a[k][j]%mo))%mo;
  31. }
  32. return c;
  33. }
  34. Matrix power(Matrix a,long long b)
  35. {
  36. Matrix c;
  37. int i;
  38. memset(c.a,,sizeof(c.a));
  39. for (i=;i<=n;i++) c.a[i][i]=;
  40. while (b)
  41. {
  42. if (b&) c=mul(c,a);
  43. b>>=;
  44. a=mul(a,a);
  45. }
  46. return c;
  47. }
  48. bool can(long long x)
  49. {
  50. long long ret=;
  51. while (x)
  52. {
  53. ret+=(x&);
  54. x>>=;
  55. }
  56. return (ret%==);
  57. }
  58. int main()
  59. {
  60. scanf("%lld%lld",&n,&k);
  61. int i,j;
  62. for (i=;i<=n;i++) scanf("%lld",&a[i]);
  63. for (i=;i<=n;i++)
  64. for (j=;j<=n;j++) st.a[i][j]=can(a[i]^a[j]);
  65. ans=power(st,k-);
  66. long long ret=;
  67. //cout<<ans.a[i][j]<<endl;
  68. for (i=;i<=n;i++)
  69. for (j=;j<=n;j++) ret=(ret+ans.a[i][j])%mo;
  70. printf("%lld\n",ret);
  71. return ;
  72. }

codeforces 691E(矩阵乘法)的更多相关文章

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

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

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

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

  3. Codeforces 400C 矩阵乘法 数学规律

    今天下午Virtual了一套最近的CF题,第三题给TLE了,就跑过去上课了. 这题给定一个由二进制表示的矩阵,当询问3的时候,求矩阵的值,矩阵的值是所有第i行乘以第i列的值的总和,然后还有1 b是翻转 ...

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

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

  5. Codeforces 1106F Lunar New Year and a Recursive Sequence | BSGS/exgcd/矩阵乘法

    我诈尸啦! 高三退役选手好不容易抛弃天利和金考卷打场CF,结果打得和shi一样--还因为queue太长而unrated了!一个学期不敲代码实在是忘干净了-- 没分该没分,考题还是要订正的 =v= 欢迎 ...

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

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

  7. Codeforces 506E - Mr. Kitayuta's Gift(神仙矩阵乘法)

    Codeforces 题目传送门 & 洛谷题目传送门 神仙题 %%%%%%%%%%%%% u1s1 感觉这道题风格很省选( 下记 \(m=|s|\),首先探讨 \(n+m\) 为偶数的情形. ...

  8. Codeforces 1368H - Breadboard Capacity(最小割+线段树维护矩阵乘法)

    Easy version:Codeforces 题面传送门 & 洛谷题面传送门 Hard version:Codeforces 题面传送门 & 洛谷题面传送门 首先看到这种从某一种颜色 ...

  9. Codeforces 750E - New Year and Old Subsequence(线段树维护矩阵乘法,板子题)

    Codeforces 题目传送门 & 洛谷题目传送门 u1s1 我做这道 *2600 的动力是 wjz 出了道这个套路的题,而我连起码的思路都没有,wtcl/kk 首先考虑怎样对某个固定的串计 ...

随机推荐

  1. 如何成为一名优秀的 iOS 开发工程师

    如果你是一位专业的iOS开发工程师,你应该为自己感到自豪.因为你能在强大的iOS系统下,一展身手实现自己和他人的想法,这是一件令人无比激动的事情. 作为一名iOS开发工程师,你一定想成为行业的佼佼者. ...

  2. 2019最新Android面试题

    原文链接:https://blog.csdn.net/wen_haha/article/details/88362469版权声明:本文为博主原创文章,转载请附上博文链接! 前言 金三银四到来了,找工作 ...

  3. robotframework + python2.7.9 + selenium 2.44.0 + selenium2library1.7 测试环境搭建成功!

    真心不容易呀!开源软件搭建挺麻烦的,各种组件未必要使用最新的版本:有些最新版本反而不兼容.需要仔细看官方说明书来进行搭建(官方网站都是英文),所以闹得重新安装了几次. 先上测试用例通过的图:

  4. LoadRunner脚本回放与设置

    一.runtime setting 1.迭代次数设置与迭代步长(循环间隔时间) 2.日志打印设置       二.实时观看回放 1.动态回放与静态回放(静态回放时,不会有逐行高亮显示:动态回放时高亮显 ...

  5. EditText自动弹出软键盘

    editText.requestFocus() editText.isFocusable = true editText.isFocusableInTouchMode = true val timer ...

  6. iOS----时间日期处理

    时间日期处理 1.NSDateFormatter 日期格式化 ①可以把NSString 类型转为 NSDate类型 举例 把 "2015-08-23 19:46:14" 转为NSD ...

  7. VBox虚拟机安装debian

    决定在win7上装一个Linux虚拟机用作Linux开发学习,虽然win7下已经有了Cygwin,还是想在一个比较完整的环境下.前面装过Ubuntu发现界面太笨重了,考虑重新换一个,同时比较喜欢apt ...

  8. 【C++】类型转换简述:四种类型转换方式的说明及应用

    本文主要简述在C++中四种类型转换的方式:static_cast.reniterpret_cast.const_cast和dynamic_cast. 在介绍C++类型转换方式之前,我们先来看看C语言的 ...

  9. 浅谈CSS中的定位知识

    1,静态定位(static) 表示按照正常定位方案,元素盒按照在文档流中出现的顺序依次格式化: 2,相对定位(relative) 将移动元素盒,但是它在文档流中的原始空间会保留下来: 相对定位元素有如 ...

  10. (转)Nutz | Nutz项目整合Spring实战

    http://blog.csdn.net/evan_leung/article/details/54767143 Nutz项目整合Spring实战 前言 Github地址 背景 实现步骤 加入spri ...