思路:刚开始 n个元素,a[i][j]代表以i开头,j结尾的二元组符合条件的有多少

这是等于长度为2的数量 长度为3的数量为a*a,所以长度为n的数量是a^(k-1)

然后就是矩阵快速幂,然而我并不能发现这道题是矩阵快速幂,没办法,太弱了

注:这个模板是从Q神的AC代码里扒下来的,仰慕Q神

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 1e2+;
const LL mod = 1e9+; LL a[],n,k;
struct Matrix{
LL a[N][N];
Matrix(){
memset(a,,sizeof(a));
}
void init(){
for(int i=;i<=n;++i)a[i][i]=;
}
Matrix operator *(const Matrix &rhs)const{
Matrix ret;
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
for(int k=;k<=n;++k)
ret.a[i][j]=(ret.a[i][j]+a[i][k]*rhs.a[k][j]%mod)%mod;
return ret;
}
Matrix operator ^(LL mi)const{
Matrix tmp=(*this),ret;
ret.init();
while(mi){
if(mi&)ret=ret*tmp;
tmp=tmp*tmp;
mi>>=;
}
return ret;
}
}; int main(){
scanf("%I64d%I64d",&n,&k);
for(int i=;i<=n;++i)
scanf("%I64d",&a[i]);
Matrix cur;
for(int i=;i<=n;++i){
for(int j=;j<=n;++j)
if(__builtin_popcountll(a[i]^a[j])%==)
++cur.a[i][j];
}
cur=cur^(k-);
LL ret=;
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
ret=(ret+cur.a[i][j])%mod;
printf("%I64d\n",ret);
return ;
}

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 691E Xor-sequences(矩阵快速幂)

    You are given n integers a1,  a2,  ...,  an. A sequence of integers x1,  x2,  ...,  xk is called a & ...

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. SDUT2484算术表达式的转换

    http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2484&cid=1182 题目描述 小明在学习了数据结构之后,突然想起了以前没有解决的算术 ...

  2. hdu 3123 GCC

    这题分2种情况: 1) n>=m时,k!%m=0(k>=m),所以只需令n=m-1即可: 2) n<m时,正常情况处理即可. ;}

  3. Java学习笔记之:Java 接口

    一.引言 接口(英文:Interface),在JAVA编程语言中是一个抽象类型,是抽象方法的集合,接口通常以interface来声明.一个类通过继承接口的方式,从而来继承接口的抽象方法. 接口并不是类 ...

  4. 百度全新的ARM架构服务器,一个2U机箱装6台,每台4个3T硬盘,每个机箱共72TB

    1月11日,中国科学院原秘书长.国家科技重大专项国务院咨询评估组专家侯自强,来到百度南京数据中心,和他一起的还有中国工程院院士倪光南以及工业和信息化部电信研究院传输研究所副所长石友康等人.他们看到的是 ...

  5. C#实现的ReplaceFirst和ReplaceLast

    原文:C#实现的ReplaceFirst和ReplaceLast ReplaceFirst: public static string ReplaceFirst(string input, strin ...

  6. [iOS]利用Appicon and Launchimage Maker生成并配置iOSApp的图标和启动页

    一.先来研究下这个软件->Appicon and Launchimage Maker 首先打开你电脑上的AppStore,然后搜索:AppIcon 然后回车: 这里我们先使用免费版的点击下载.( ...

  7. 87. Scramble String

    题目: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty subs ...

  8. 【c++】中文设置

    #include <iostream> #include <string> #include<locale> using namespace std; ; int ...

  9. Mysql:常用代码

    C/S: Client Server B/S: Brower Server Php主要实现B/S .net IIS Jave TomCat LAMP:L Mysql:常用代码 Create table ...

  10. Hibernate HQL查询的参数绑定

    参数绑定: Hibernate中对动态查询参数绑定提供了丰富的支持,那么什么是查询参数动态绑定呢?其实如果我们熟悉传统JDBC编程的话,我们就不难理解查询参数动态绑定,如下代码传统JDBC的参数绑定: ...