Educational Codeforces Round 14 E.Xor-sequences
分析:K很大,以我现有的极弱的知识储备,大概应该是快速幂了。。。怎么考虑这个快速幂呢,用到了dp的思想。定义dp[i][j]表示从a[i]到a[j]的合法路径数。那么递推式就是dp[i][j]=∑k(dp[i][k]∗dp[k][j])。每次进行这样一次计算,那么序列的长度就会增加一,因此只要将这个式子做k次就行了。怎么满足相邻两个数异或值的1的个数为3倍数呢?这就是用到矩阵的时候了。枚举ij,建立一个N∗N的矩阵,当a[i]⊗a[j]为3的倍数,m[i][j]为1,否则为零。再考虑到矩阵的乘法其实和刚才的dp递推式是一样的??!!因此只要将矩阵乘K−1次就行了。
/*****************************************************/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <map>
#include <set>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define offcin ios::sync_with_stdio(false)
#define sigma_size 26
#define lson l,m,v<<1
#define rson m+1,r,v<<1|1
#define slch v<<1
#define srch v<<1|1
#define sgetmid int m = (l+r)>>1
#define LL long long
#define ull unsigned long long
#define mem(x,v) memset(x,v,sizeof(x))
#define lowbit(x) (x&-x)
#define bits(a) __builtin_popcount(a)
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const int INF = 0x3f3f3f3f;
const LL INFF = 1e18;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-9;
const LL mod = 1e9+7;
const int maxmat = 10;
const ull BASE = 31;
/*****************************************************/
const int maxn = 1e2 + 5;
LL p[maxn];
struct Mat {
int n;
LL a[105][105];
Mat(int _n = 0) : n(_n) {mem(a, 0);}
Mat operator *(const Mat &rhs) const {
int n = rhs.n;
Mat c(n);
for (int i = 0; i < n; i ++)
for (int j = 0; j < n; j ++)
for (int k = 0; k < n; k ++)
c.a[i][j] = (c.a[i][j] + a[i][k] * rhs.a[k][j] % mod) % mod;
return c;
}
};
int count(LL k) {
int ans = 0;
while (k) {
if (k & 1) ans ++;
k >>= 1;
}
return ans;
}
Mat qpow(Mat A, LL b) {
int n = A.n;
Mat c(n);
for (int i = 0; i < n; i ++) c.a[i][i] = 1;
while (b) {
if (b & 1) c = c * A;
b >>= 1;
A = A * A;
}
return c;
}
int main(int argc, char const *argv[]) {
int N;
LL K;
cin>>N>>K;
for (int i = 0; i < N; i ++) cin>>p[i];
Mat A(N);
for (int i = 0; i < N; i ++)
for (int j = 0; j < N; j ++)
if (count(p[i] ^ p[j]) % 3 == 0)
A.a[i][j] = 1;
A = qpow(A, K - 1);
LL ans = 0;
for (int i = 0; i < N; i ++)
for (int j = 0; j < N; j ++)
ans = (ans + A.a[i][j]) % mod;
cout<<ans<<endl;
return 0;
}
Educational Codeforces Round 14 E.Xor-sequences的更多相关文章
- Educational Codeforces Round 14 D. Swaps in Permutation (并查集orDFS)
题目链接:http://codeforces.com/problemset/problem/691/D 给你n个数,各不相同,范围是1到n.然后是m行数a和b,表示下标为a的数和下标为b的数可以交换无 ...
- Educational Codeforces Round 14 D. Swaps in Permutation(并查集)
题目链接:http://codeforces.com/contest/691/problem/D 题意: 题目给出一段序列,和m条关系,你可以无限次互相交换这m条关系 ,问这条序列字典序最大可以为多少 ...
- Educational Codeforces Round 14 D. Swaps in Permutation 并查集
D. Swaps in Permutation 题目连接: http://www.codeforces.com/contest/691/problem/D Description You are gi ...
- Educational Codeforces Round 14 C. Exponential notation 数字转科学计数法
C. Exponential notation 题目连接: http://www.codeforces.com/contest/691/problem/C Description You are gi ...
- Educational Codeforces Round 14 B. s-palindrome 水题
B. s-palindrome 题目连接: http://www.codeforces.com/contest/691/problem/B Description Let's call a strin ...
- Educational Codeforces Round 14 A. Fashion in Berland 水题
A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...
- Educational Codeforces Round 14 - F (codeforces 691F)
题目链接:http://codeforces.com/problemset/problem/691/F 题目大意:给定n个数,再给m个询问,每个询问给一个p,求n个数中有多少对数的乘积≥p 数据范围: ...
- Educational Codeforces Round 14 D. Swaps in Permutation
题目链接 分析:一些边把各个节点连接成了一颗颗树.因为每棵树上的边可以走任意次,所以不难想出要字典序最大,就是每棵树中数字大的放在树中节点编号比较小的位置. 我用了极为暴力的方法,先dfs每棵树,再用 ...
- Educational Codeforces Round 14
A - Fashion in Berland 水 // #pragma comment(linker, "/STACK:102c000000,102c000000") #inclu ...
随机推荐
- DuiLib学习笔记2——写一个简单的程序
我们要独立出来自己创建一个项目,在我们自己的项目上加皮肤这才是初衷.我的新建项目名为:duilibTest 在duilib根目录下面有个 Duilib入门文档.doc 我们就按这个教程开始入门 首先新 ...
- sprint3终极演示
目标功能: 已实现功能: 首页.订单.资料界面 首页.订单.资料按钮 化妆师.化妆品.化妆视频按钮 化妆师.化妆品的详细分类 化妆师.化妆品的详细信息显示 化妆师的预约按钮和联系按钮 化妆品的购买按钮 ...
- Leetcode: All O`one Data Structure
Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...
- c/c++ 数据结构 链表插入数据代码(一)
链表插入数据,有两种方法,链表头定义为指针. 1.指针传递 #include <stdio.h> #include <stdlib.h> typedef struct LNod ...
- sdutoj 2624 Contest Print Server
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2624 Contest Print Server ...
- Win7常规快捷键
Win7常规快捷键: Win+1:打开/显示超级任务栏第一个图标代表的程序 Win+2:打开/显示超级任务栏第二个图标代表的程序(3.4.--如此类推) Win+D:切换桌面显示窗口或者gadgets ...
- tp生成验证码
视图层: <input type="text" name="code" value="" /> <img o ...
- 本地yum库制作及本地安装Docker
生产环境中,我们总是会遇到服务器无法连接外网的情况,这样,如果想安装某个应用,而这个应用依赖的其他类库又特别多,就很痛苦了.这个时候,就需要自己制作个本地的yum库,进行本地安装.本文将以Docker ...
- [课程设计]Scrum 1.7 多鱼点餐系统开发进度(点餐菜式内容添加及美化)
[课程设计]Scrum 1.7 多鱼点餐系统开发进度(点餐菜式内容添加及美化) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选题 ...
- 从yum源下载安装包及依赖包
局域网内所有linux都用yum从外网源安装软件有点浪费,尤其遇到下载慢的情况: 所以考虑下载后传到其他机器安装,还可以保证版本一致(创建一个本地仓库更好,这个后面研究了再记录): 首先安装yum工具 ...