题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6172

题意:如题。

解法:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;
struct Matrix{
LL a[3][3];
void set1(){
memset(a, 0, sizeof(a));
}
void set2(){
memset(a, 0, sizeof(a));
for(int i=0; i<3; i++) a[i][i]=1;
}
void set3()
{
a[0][0]=4,a[0][1]=17,a[0][2]=-12;
a[1][0]=1,a[1][1]=0,a[1][2]=0;
a[2][0]=0,a[2][1]=1,a[2][2]=0;
}
};
Matrix operator * (const Matrix &a, const Matrix &b){
Matrix res;
res.set1();
for(int i=0; i<3; i++){
for(int j=0; j<3; j++){
for(int k=0; k<3; k++){
res.a[i][j] = (res.a[i][j]%mod+a.a[i][k]*b.a[k][j]%mod + mod)%mod;
}
}
}
return res;
}
Matrix qsm(Matrix a, LL n){
Matrix res;
res.set2();
while(n){
if(n&1) res = res*a;
a = a*a;
n/=2LL;
}
return res;
} int main()
{
int T;
scanf("%d", &T);
while(T--)
{
LL n;
scanf("%lld", &n);
if(n==2){
puts("31");
}
else if(n==3){
puts("197");
}
else if(n==4){
puts("1255");
}
else{
Matrix A,B;
A.set3();
B = qsm(A, n-4);
LL ans = (B.a[0][0]*1255%mod+B.a[0][1]*197%mod+B.a[0][2]*31%mod+mod)%mod;
printf("%lld\n", ans%mod);
}
}
return 0;
}

2017多校第10场 HDU 6172 Array Challenge 猜公式,矩阵幂的更多相关文章

  1. 2017多校第10场 HDU 6178 Monkeys 贪心,或者DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:给出一棵有n个节点的树,现在需要你把k只猴子放在节点上,每个节点最多放一只猴子,且要求每只 ...

  2. 2017多校第10场 HDU 6171 Admiral 双向BFS或者A*搜索

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6171 题意: 给你一个高度为6的塔形数组,你每次只能将0与他上下相邻的某个数交换,问最少交换多少次可以 ...

  3. 2017多校第10场 HDU 6181 Two Paths 次短路

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6181 题意:给一个图,求出次短路. 解法:我之前的模板不能解决这种图,就是最短路和次短路相等的情况,证 ...

  4. 2017多校第10场 HDU 6180 Schedule 贪心,multiset

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并 ...

  5. 2017多校第7场 HDU 6127 Hard challenge 极角排序,双指针

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6127 题意:平面直角坐标系上有n个整点,第i个点有一个点权val​,坐标为(xi,yi),其中不存在任 ...

  6. 2017多校第9场 HDU 6161 Big binary tree 思维,类似字典树

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6161 题意: 题目是给一棵完全二叉树,从上到下从左到右给每个节点标号,每个点有权值,初始权值为其标号, ...

  7. 2017多校第9场 HDU 6169 Senior PanⅡ 数论,DP,爆搜

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6169 题意:给了区间L,R,求[L,R]区间所有满足其最小质数因子为k的数的和. 解法: 我看了这篇b ...

  8. 2017多校第8场 HDU 6138 Fleet of the Eternal Throne AC自动机或者KMP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6138 题意:给n个串,每次询问x号串和y号串的最长公共子串的长度,这个子串必须是n个串中某个串的前缀 ...

  9. 2017多校第8场 HDU 6134 Battlestation Operational 莫比乌斯反演

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6134 题意: 解法: 那么g(n)怎么求,我们尝试打表发现g(n)是有规律的,g(n)=g(n-1)+ ...

随机推荐

  1. PowerDesigner 建表语句没出现字段描述

    填写了Name 还是没有 修改步骤如下:

  2. [SOJ #48]集合对称差卷积

    题目大意:给你两个多项式$A,B$,求多项式$C$使得: $$C_n=\sum\limits_{x\oplus y=n}A_xB_y$$题解:$FWT$ 卡点:无 C++ Code: #include ...

  3. BZOJ1040:[ZJOI2008]骑士——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1040 题面大意:n个人有一个价值和一个最恨的人,现在组出一个队伍使得价值最大且没有仇恨关系. ——— ...

  4. ContestHunter暑假欢乐赛 SRM 09(TJM大傻逼选手再创佳绩)

    T1 f[i]为前i页最少被撕几页,用二分转移就行了,答案为ans=min(f[i]+(n-i)); 不知道为什么写挂了嗯 二分的l初始应该是0 T2 数位DP f[i][1/0][1/0][1/0] ...

  5. 获取指定IP地址对应的物理位置

    # -*- coding: utf-8 -*- import requests def get_physical_location(ip): url = 'http://ip.taobao.com/s ...

  6. JavaScript中字符串与16进制之间的转换

    一.字符串转换为16进制 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  7. [codeforces/edu31]总结

    链接:http://codeforces.com/contest/884 A题: 求86400-ai的前缀和,找到第一个大于等于给定t的即可. B题: 任意相邻两段之间必然有一个0,然后算一下至少的长 ...

  8. ringbuffer

    http://blog.csdn.net/xiaolang85/article/details/38419163

  9. Selenium判断获取的元素是否可见(display:none)

    在爬虫中需要自动登陆并判断是否登陆成功,如果登陆错误的话还需要知道错误提示信息,此时需要判断提示信息是否可见 if self.element_exist_xpath('//*[@id="bu ...

  10. Mabatis(2) 全局配置文件

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC & ...