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 ...
随机推荐
- windows nslookup、tracert 常用命令
nslookup www.baidu.com 可以指定查询的类型,可以查到DNS记录的生存时间还可以指定使用哪个DNS服务器进行解释. tracert www.baidu.com 路由
- 使用回车键代替TAB键 需jquery1.4.2版本
1 $(document).ready(function () { 2 $(':input:text:first').focus(); 3 $(':input:enabled').addClass(' ...
- zjuoj 3608 Signal Detection
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3608 Signal Detection Time Limit: 2 Sec ...
- Debian系列Linux/Ubuntu 安装软件
wps(http://community.wps.cn/download/) 优客天气(https://launchpad.net/indicator-china-weather/+download) ...
- confluence重置admin密码
复方法: 1. 运行此sql 找到你的管理员帐户: select u.id, u.user_name, u.active from cwd_user u join cwd_membership m o ...
- RunTime的一些用法
RunTime的一些用法 RunTime简介 RunTime简称运行时.OC就是运行时机制,其中最主要的是消息机制 对于OC来说,在编译的时候并不能决定真正调用哪个函数,只有真正运行时才会根据函数 ...
- 如何清理photoshop cs6 被升级的烦人的adobe creative cloud组件
安装photoshop cs6(虽然目前已经退出到cc 2015,不过因激活成熟度等,我还是偏向于使用cs6,够用!),默认安装adobe application manager. 不过如果不小心单独 ...
- ubuntu常用命令记录集
1.查找当前目录下包含某字符串的文件 #find ./ -type f |xargs grep "string" 2.查找文件 #find ./ -name filename 3. ...
- 回传数据startActivityForResult()
1.调用者Activity01开启新的界面选用startActivityForResult(intent,requestCode);在Activity01中Intent intent=new Inte ...
- 不用安装Oracle_Client就能使用PLSQL_Developer
1. 下载oracle的客户端程序包(30M) 只需要在Oracle官方网站下载一个叫Instant Client Package的软件就可以了,这个软件不需要安装,只要解压就可以用了,很 ...