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 ...
随机推荐
- Scala 环境搭建
下载安装包 1,)下载java jdk,推荐jdk1.8; 2,)下载scala安装包:http://www.scala-lang.org/; 3,)下载IDE:ide可以选择两种: 3.1,)Sca ...
- 向ES6看齐,用更好的JavaScript(二)
本文是ES6系列的第二篇,主要介绍ES6中对现有对象方法属性的拓展,先上传送门: 1 变量部分 2 现有对象拓展 3 新增数据类型/数据结构 4 新的异步编程模式 5 类和模块 1 增加了模板字符串 ...
- PostgreSQL中数据库,表,等对象的oid与对象名的对应关系
-bash-4.1$ oid2name Password: All databases: Oid Database Name Tablespace--------------------------- ...
- 【Selenium】1.介绍 Selenium
本文供学习交流之用,没有商业用途,没有盈利. 完全是我自己为督促自己学习而翻译的.翻译的不好,见谅.来源于:http://www.guru99.com/introduction-to-selenium ...
- 设计模式_11_原型模式(prototype)深拷贝、浅拷贝
设计模式_11_原型模式(prototype) 浅拷贝: package designPatternOf23; /** * 定义:用原型实例,指定创建对象的种类,并通过拷贝这些原型创建新的对象 * P ...
- Gulp学习指南之CSS合并、压缩与MD5命名及路径替换(转载)
本文转载自: Gulp学习指南之CSS合并.压缩与MD5命名及路径替换
- mysql中and和or
and的优先级高于or,所以一个sql语句中如果and和or同时出现,则or要加括号
- 在 ASP.NET 中使用 jQuery.load() 方法
今天就让我们看看在 ASP.NET 中使用 jQuery.load() 方法来调用 ASP.NET 的方法,实现无刷新的加载数据. 使用 jQuery 的朋友应该知道可以使用 jQuery.load( ...
- AppleWatch___学习笔记(二)UI布局和UI控件
1.UI布局 直接开发,你会发现Apple Watch并不支持AutoLayout,WatchKit里有个类叫做WKInterfaceGroup,乍一看像是UIView,但是这货其实是用来布局的.从 ...
- Visual Studio常用插件
Visual Assist X 番茄不用说了,C# C++编码必备 Image Insertion 可以在代码编辑器中插入图片注释,让代码像Word文档一样图文并茂. 但注意必须是PNG格式的图片,直 ...