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) 然后就是矩阵快速幂,然而我并不能 ...
随机推荐
- 基于Tesseract的身份证识别Android端应用
以开源的Tesseract为基础,做了一个身份证识别的app. 图片资源是百度找的,而且手机对着电脑屏幕拍照,拍出很多花纹,影响比较大,所以误差不小,实测对着自己身份证拍照会好很多. 效果图: 1.拍 ...
- python学习——练习题(10)
""" 题目:暂停一秒输出,并格式化当前时间. """ import sys import time def answer1(): &quo ...
- 跟着太白老师学python day10 函数嵌套, global , nonlocal
函数嵌套: 第一种嵌套方法 def func(): count = 123 def inner(): print(count) inner() func() 第二种嵌套方法 count = 123 d ...
- C++Primer笔记-----day03
==============================================================day03================================= ...
- ubuntu系统中出现mysql数据库无法启动报错2002该怎么处理,具体报错信息如正文所示
python@ubuntu:~$ mysql -uroot -pmysqlmysql: [Warning] Using a password on the command line interface ...
- 网页静态化—redis | freemarker
1. 学习计划 1.商品详情页面展示,动态展示 jsp + redis 2.使用freemarker实现网页静态化 3.ActiveMq同步生成静态网页 两个方案对比,方案一依赖web容器,red ...
- java求最长公共子串的长度
1这道题目就是给定两个字符串,然后求这两个字符串的最长公共子串的最大长度,假设我的f()方法是来求两个字符串的最大公共子串,从头开始逐一比较,如果相等,则 继续调用这个方法,使得递归的长度+1,如果不 ...
- MySQL 基础常用命令
一.启动与关闭 1.1 Linux下启动mysql 的命令: a. rpm包安装:service mysqld start b. 源码包安装:/usr/local/mysql/bin/mysqld_s ...
- HQL多表查询
------------------siwuxie095 HQL 多表查询 以客户和联系人为例(一对多) 1.内连接 (1)hql 语句写法 from Customer c inner join c. ...
- 为什么ajax发GET请求就成功,POST请求则报错?
为什么ajax发GET请求就成功,POST请求则报错? (1)首先说明的是请求的URL是一个静态资源,比如一个json文件.(2)现在现象是发GET请求就成功,POST请求则报错.(3)最新发现:就算 ...