codeforces 691E Xor-sequences 矩阵快速幂
思路:刚开始 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 矩阵快速幂的更多相关文章
- 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 691E Xor-sequences(矩阵快速幂)
You are given n integers a1, a2, ..., an. A sequence of integers x1, x2, ..., xk is called a & ...
- 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异或的二 ...
随机推荐
- 只有innoDB才允许使用外键
1.只有InnoDB引擎才允许使用外键,所以,我们的数据表必须使用InnoDB引擎. 2.注意: 1.必须使用InnoDB引擎: 2.外键必须建立索引(INDEX): 3.外键绑定关系这里使用了“ O ...
- 【转】Windows Server 2008修改远程桌面连接数
按照下面的设置是成功了的,我设置的连接数是5个. http://jingyan.baidu.com/article/154b463150d1b128ca8f4194.html
- ossec 常用命令及目录说明
1. /var/www/html/analogi -> ossec 第三方的web界面的安装目录 [root@ossec-server ~]# cd /var/www/html/analogi/ ...
- Java API —— Date类
1.Date类概述 类 Date 表示特定的瞬间,精确到毫秒. 2.构造方法 public Date():分配 Date 对象并初始化此对象,以表示分配它的时间(精确到毫秒). public Dat ...
- 安卓开发44:解决 INSTALL_FAILED_UID_CHANGED 等问题
apk无法卸载,一般可以下面的方法试一下: 1. 删除/data/app/(filename) 文件夹下的apk包 2. 删除/system/app/(filename) 文件夹下的apk包 3. 将 ...
- BZOJ 2301 Problem b(莫比乌斯函数)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2301 题意:每次给出a,b,c,d,K.求有多少数对(x,y)满足a<=x< ...
- Android开发之EventBus的简单使用
参考: 1.http://blog.csdn.net/harvic880925/article/details/40660137 2.http://blog.csdn.net/harvic880925 ...
- 1227. Rally Championship
1227 题意木看懂 是可以停在路上 任何地方 水题一枚 以下条件之一满足就可以 有环(并查集判) 重边 自己到自己的边 最长边大于s(用flod改写下) #include <iostream& ...
- hdu 4941 Magical Forest ( 双重map )
题目链接 题意: 有一个n*m的田地,里边有k棵树,每棵树的位置为(xi,yi),含有能量值ci.之后又q个询问,分三种; 1)1 a b,将a行和b行交换 2)2 a b,将a列和b列交换 3)3 ...
- Error Curves(2010成都现场赛题)
F - Error Curves Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descript ...