题目链接

分析: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的更多相关文章

  1. Educational Codeforces Round 14 D. Swaps in Permutation (并查集orDFS)

    题目链接:http://codeforces.com/problemset/problem/691/D 给你n个数,各不相同,范围是1到n.然后是m行数a和b,表示下标为a的数和下标为b的数可以交换无 ...

  2. Educational Codeforces Round 14 D. Swaps in Permutation(并查集)

    题目链接:http://codeforces.com/contest/691/problem/D 题意: 题目给出一段序列,和m条关系,你可以无限次互相交换这m条关系 ,问这条序列字典序最大可以为多少 ...

  3. Educational Codeforces Round 14 D. Swaps in Permutation 并查集

    D. Swaps in Permutation 题目连接: http://www.codeforces.com/contest/691/problem/D Description You are gi ...

  4. Educational Codeforces Round 14 C. Exponential notation 数字转科学计数法

    C. Exponential notation 题目连接: http://www.codeforces.com/contest/691/problem/C Description You are gi ...

  5. Educational Codeforces Round 14 B. s-palindrome 水题

    B. s-palindrome 题目连接: http://www.codeforces.com/contest/691/problem/B Description Let's call a strin ...

  6. Educational Codeforces Round 14 A. Fashion in Berland 水题

    A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...

  7. Educational Codeforces Round 14 - F (codeforces 691F)

    题目链接:http://codeforces.com/problemset/problem/691/F 题目大意:给定n个数,再给m个询问,每个询问给一个p,求n个数中有多少对数的乘积≥p 数据范围: ...

  8. Educational Codeforces Round 14 D. Swaps in Permutation

    题目链接 分析:一些边把各个节点连接成了一颗颗树.因为每棵树上的边可以走任意次,所以不难想出要字典序最大,就是每棵树中数字大的放在树中节点编号比较小的位置. 我用了极为暴力的方法,先dfs每棵树,再用 ...

  9. Educational Codeforces Round 14

    A - Fashion in Berland 水 // #pragma comment(linker, "/STACK:102c000000,102c000000") #inclu ...

随机推荐

  1. RDIFramework.NET ━ 9.11 数据字典管理 ━ Web部分

    RDIFramework.NET ━ .NET快速信息化系统开发框架 9.11  数据字典管理 -Web部分  数据字典模块主要对框架所需数据字典(即选项数据)进行管理,整个数据字典数据为框架所共享, ...

  2. javascript面向对象详解

    认识面向对象 1.面向对象中的概念 一切事物皆对象 对象具有封装和继承特性 信息隐藏 2.基本面向对象 3.函数构造器构造对象 深入了解面向对象 第一种书写格式 第二种书写格式

  3. jquery-mobile之loading加载自定义

    用jquery-mobile的时候,我们发现文档中loading是直接通过标签属性进行渲染,封装的函数必须通过点击按钮才能执行.而实际运用中,我们的加载开始和结束可能不需要点击,而是通过某个函数调用直 ...

  4. 13. 星际争霸之php设计模式--正面模式

    题记==============================================================================本php设计模式专辑来源于博客(jymo ...

  5. 解决qt程序的链接阶段出现 undefined reference 错误

    错误的原因是我使用到了 QT Widgets 模块中的东西,但是makefile的链接的参数中没有 widgets.其实官网上提到了这个: http://doc.qt.io/qt-5/qtwidget ...

  6. MSDeploy

    http://blogs.iis.net/jamescoo/default.aspx   Web Deployment Tool Now Works With Credential Store Feb ...

  7. Openstack安全规则说明

    openstack的安全规则,主要是在网络控制器,nova-network中进行的端口限制,所以我们需要对规则进行定制. 定制通用安全组规则 通用安全组规则主要包括2个,1是支持ping的icmp协议 ...

  8. Linux按键驱动程序设计--从简单到不简单【转】

    本文转载自:http://blog.csdn.net/coding__madman/article/details/51399353 混杂设备驱动模型: 1. 混杂设备描述 在Linux系统中,存在一 ...

  9. 为您详细比较三个 CSS 预处理器(框架):Sass、LESS 和 Stylus

    CSS 预处理器技术已经非常的成熟,而且也涌现出了越来越多的 CSS 的预处理器框架.本文向你介绍使用最为普遍的三款 CSS 预处理器框架,分别是 Sass.Less CSS.Stylus. 首先我们 ...

  10. CSS 笔记六(Image/Attribute Selectors)

    Image Opacity / Transparency The CSS opacity property is a part of the CSS3 recommendation. Example ...