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) 然后就是矩阵快速幂,然而我并不能 ...
随机推荐
- Flask之模板web表单
3.3 Web表单: web表单是web应用程序的基本功能. 它是HTML页面中负责数据采集的部件.表单有三个部分组成:表单标签.表单域.表单按钮.表单允许用户输入数据,负责HTML页面数据采集,通过 ...
- C#中的数据格式转换 (未完待更新)
一.string to int int intA = 0;1.intA =int.Parse(str);2.int.TryParse(str, out intA);3.intA = Convert.T ...
- 跟着太白老师学python day11 可迭代对象和迭代器
如果对象的属性中有__iter__属性就说明是可迭代的,容器类的数据类型都是可迭代对象 如果对象的属性中既有__iter__属性也有__next__属性,就说明这个对象是迭代器 如何判断一个函数是不是 ...
- linux查找目录下的所有文件中是否含有某个字符串 <zhuan>
查找目录下的所有文件中是否含有某个字符串 find .|xargs grep -ri "IBM" 查找目录下的所有文件中是否含有某个字符串,并且只打印出文件名 find .|xar ...
- Git(三):Git 使用规范流程
转:http://www.ruanyifeng.com/blog/2015/08/git-use-process.html 团队开发中,遵循一个合理.清晰的Git使用流程,是非常重要的. 否则,每个人 ...
- UNITY IMGUI
这几天研究OPENGL时,想找一个UI库来用,发现了IMGUI,到网上搜索评估中,突然发现它似乎和UNITY有关系. UNITY文档中提到过IMGUI,不知道是不一个东西,仔细看了下文档,果然是.原文 ...
- GameObject.DestroyImmediate(go, true)会使磁盘资源数据丢失,导致不可用
GameObject.DestroyImmediate(go, true)会使磁盘资源数据丢失,导致不可用 第二个参数true表示 allowDestroyingAssets,表示允许销毁资源. 实测 ...
- UNITY所谓的异步加载几乎全部是协程,不是线程;MAP3加载时解压非常慢
实践证明,以下东西都是协程,并非线程(thread): 1,WWW 2,AssetBundle.LoadFromFileAsync 3,LoadSceneAsync 其它未经测试 此问题的提出是由于一 ...
- 理解python中的元类
一,理解类也是对象 在python中类同样也是一种对象,只要使用关键字class,Python解释器在执行的时候就会创建一个对象,这个对象(类)自身拥有创建对象(类实例)的能力,这就是为什么他是一个类 ...
- cdoj1088-王之迷宫 (三维迷宫最短路径)【BFS】
http://acm.uestc.edu.cn/#/problem/show/1088 王之迷宫 Time Limit: 3000/1000MS (Java/Others) Memory Li ...