Codeforces 691E Xor-sequences【矩阵快速幂,好题】
来源:互联网 发布:淘宝店铺logo免费设计 编辑:程序博客网 时间:2024/05/17 00:07
题意:
给定序列,从序列中选择
分析:
首先每个元素自己构成一个长度为
其次我们可以预处理出满足条件的
接下来我们发现,两个矩阵相乘,矩阵
接下来用矩阵
依次乘
最后把得到的矩阵中的每个元素的值加起来即为长度为
实质上就是
巧妙的利用矩阵乘法的性质解决问题!这很矩阵!
#include<cstdio>#include<iostream>#include<cstdlib>#include<queue>#include<cstring>#include<stack>#include<vector>#include<algorithm>#include<map>#include<cmath>using namespace std;#define pr(x) cout << #x << ": " << x << " "#define pl(x) cout << #x << ": " << x << endl;#define sa(x) scanf("%d",&(x))#define sal(x) scanf("%I64d",&(x))typedef long long ll;const int maxn = 105, mod = 1e9 + 7;ll a[maxn];int n;const int N = 105;struct Matrix{ int row,cal; long long m[N][N];};Matrix init(Matrix a, long long t){ for(int i = 0; i < a.row; i++) for(int j = 0; j < a.cal; j++) a.m[i][j] = t; return a;}Matrix mul(Matrix a,Matrix b){ Matrix ans; ans.row = a.row, ans.cal = b.cal; ans = init(ans,0); for(int i = 0; i < a.row; i++) for(int j = 0; j < b.cal; j++) for(int k = 0; k < a.cal; k++) ans.m[i][j] = (ans.m[i][j] + a.m[i][k] * b.m[k][j])%mod; return ans;}Matrix quick_pow(long long k, Matrix A){ Matrix I; I.row = n, I.cal = n; I = init(I, 0); for(int i = 0; i < n; i++){ I.m[i][i] = 1; } while(k){ if(k & 1) I = mul(I, A); A = mul(A, A); k >>= 1; } return I;}int count(ll a){ int ans = 0; while(a){ if(a & 1) ans++; a >>= 1; } return ans;}int main(void){ sa(n); ll k;sal(k); for(int i = 0; i < n; i++){ sal(a[i]); } Matrix A; A.row = n, A.cal = n; A = init(A, 0); for(int i = 0 ; i < n; i++){ for(int j = 0; j < n; j++){ if(count(a[i] ^ a[j]) % 3 == 0){ A.m[i][j] = 1; } } } ll ans = 0; A = quick_pow(k - 1, A); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ (ans += A.m[i][j]) %= mod; } } printf("%I64d\n", ans); return 0;}
0 0
- Codeforces 691E Xor-sequences【矩阵快速幂,好题】
- Codeforces 691E Xor-sequences【矩阵快速幂,好题】
- Codeforces 691E Xor-sequences(矩阵快速幂)
- Codeforces 691 E Xor-sequences 矩阵快速幂
- CodeForces-691E Xor-sequences(矩阵快速幂)
- codeforces 691E Xor-sequences(矩阵快速幂)
- CF 691E Xor-sequences 矩阵快速幂 + dp
- Educational Codeforces Round 14 E.Xor-sequences
- Codeforces Round #341 (Div. 2)E(矩阵快速幂优化dp,好题)
- Codeforces 450B Jzzhu and Sequences(矩阵快速幂)
- Codeforces #257B Jzzhu and Sequences(矩阵快速幂)
- CodeForces 450BJzzhu and Sequences 矩阵快速幂
- Codeforces 450B Jzzhu and Sequences(矩阵快速幂)
- Codeforces 450B-Jzzhu and Sequences (矩阵快速幂)
- codeforces 450-B Jzzhu and Sequences 矩阵快速幂
- Codeforces 450B Jzzhu and Sequences(矩阵快速幂)
- Codeforces 514E 矩阵快速幂
- Codeforces 426E Sereja and Two Sequences【思维+Dp+二分】好题!
- 51nod-1405 树的距离之和
- DigitRecongnizer_CNN_DeepLearning
- 课堂小结——Html中的几种布局简单比较
- 生成随机数源代码-C++
- 【UE4学习】13_UFUNCTION 关键字解释
- Codeforces 691E Xor-sequences【矩阵快速幂,好题】
- 分布式理论之一:Paxos算法的通俗理解
- Burp Suite出了一个类似cloudeye.me的功能
- lnmp下配置PHP虚拟主机vhost
- 用Meta标签代码让360双核浏览器默认极速模式打开网站不是兼容模式
- CSS3快速上手之18:图片的格式操作
- 一些安全软件
- Jersey_Client程序的编写和运行
- Makefile详解