http://www.lightoj.com/volume_showproblem.php?problem=1244

题意:给出六种积木,不能旋转,翻转,问填充2XN的格子有几种方法。\(N <= 10^9 \)

思路:首先手写出前几项,猜出递推式,如果真有比赛出这种题,又不能上网进工具站查是吧?N比较大显然用矩阵快速幂优化一下

/** @Date    : 2016-12-18-22.44
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version :
*/
#include<bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; const LL mod = 1e4 + 7;
struct matrix
{
LL mt[3][3];
void init()
{
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
mt[i][j] = 0;
}
void cig()
{
for(int i = 0; i < 3; i++)
mt[i][i] = 1;
}
}; matrix mul(matrix a, matrix b)
{
matrix c;
c.init();
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
for(int k = 0; k < 3; k++)
{
c.mt[i][j] += a.mt[i][k] * b.mt[k][j];
c.mt[i][j] %= mod;
}
}
}
return c;
} matrix fpow(matrix a, LL n)
{
matrix r;
r.init();
r.cig();
while(n > 0)
{
if(n & 1)
r = mul(r, a);
a = mul(a, a);
n >>= 1;
}
return r;
} LL fun(LL n)
{
if(n < 3)
{
return n;
}
matrix base;
base.init();
base.mt[0][0] = 2;
base.mt[0][2] = 1;
base.mt[1][0] = 1;
base.mt[2][1] = 1;
base = fpow(base, n - 3);
return (base.mt[0][0] * 5 + base.mt[0][1] * 2 + base.mt[0][2]) % mod; }
int main()
{
int T;
int cnt = 0;
cin >> T;
while(T--)
{
LL n;
scanf("%lld", &n);
LL ans = fun(n);
printf("Case %d: %lld\n", ++cnt, ans);
}
return 0;
}

LightOJ 1244 - Tiles 猜递推+矩阵快速幂的更多相关文章

  1. HDU 5950 Recursive sequence 【递推+矩阵快速幂】 (2016ACM/ICPC亚洲区沈阳站)

    Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  2. hdu 2604 递推 矩阵快速幂

    HDU 2604 Queuing (递推+矩阵快速幂) 这位作者讲的不错,可以看看他的 #include <cstdio> #include <iostream> #inclu ...

  3. HDU 2842 (递推+矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题目大意:棒子上套环.第i个环能拿下的条件是:第i-1个环在棒子上,前i-2个环不在棒子上.每个 ...

  4. Recursive sequence HDU - 5950 (递推 矩阵快速幂优化)

    题目链接 F[1] = a, F[2] = b, F[i] = 2 * F[i-2] + F[i-1] + i ^ 4, (i >= 3) 现在要求F[N] 类似于斐波那契数列的递推式子吧, 但 ...

  5. HDU6030 Happy Necklace(递推+矩阵快速幂)

    传送门:点我 Little Q wants to buy a necklace for his girlfriend. Necklaces are single strings composed of ...

  6. 五校联考R1 Day1T3 平面图planar(递推 矩阵快速幂)

    题目链接 我们可以把棱柱拆成有\(n\)条高的矩形,尝试递推. 在计算的过程中,第\(i\)列(\(i\neq n\))只与\(i-1\)列有关,称\(i-1\)列的上面/下面为左上/左下,第\(i\ ...

  7. [递推+矩阵快速幂]Codeforces 1117D - Magic Gems

    传送门:Educational Codeforces Round 60 – D   题意: 给定N,M(n <1e18,m <= 100) 一个magic gem可以分裂成M个普通的gem ...

  8. 2017中国大学生程序设计竞赛 - 女生专场 Happy Necklace(递推+矩阵快速幂)

    Happy Necklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  9. [hdu 2604] Queuing 递推 矩阵快速幂

    Problem Description Queues and Priority Queues are data structures which are known to most computer ...

随机推荐

  1. Eclipse/myEclipse 代码提示/自动提示/自动完成设置(转)

    一.设置超级自动提示 设置eclipse/myEclipse代码提示可以方便开发者,不用在记住拉杂的单词,只用打出首字母,就会出现提示菜单.如同dreamweaver一样方便. 1.菜单window- ...

  2. 读我是一只IT小小鸟有感

    进入大学半年了,每个人都说软件工程是一个非常有前途的高薪职业,但我这半年来都很迷茫,看不清自己的未来,不知道如何度过接下来的三年半时光,虽然我也认为软件工程是有前途的专业,但是经过一学期的学习,发现不 ...

  3. PAT 甲级 1077 Kuchiguse

    https://pintia.cn/problem-sets/994805342720868352/problems/994805390896644096 The Japanese language ...

  4. IntelliJ IDEA 创建 hello world Java web Maven项目从头到尾都有图有真相2017版本

    学Java的大部分吧都是要整Java web开发项目的,那么最好用的编辑器估计就是这个 IntelliJ IDEA,然后现在maven管理项目是很流行的.然后我就示范一下,如何使用这个IntelliJ ...

  5. 【转载】mysql建表date类型不能设置默认值

    如题,mysql建表date类型的不能设置一个默认值,比如我这样: CREATE TABLE `new_table` ( `biryhday` datetime NULL DEFAULT '1996- ...

  6. python编码iso-8859-9编码问题

    (2018-10-15) 路 2018骞�10鏈�16鏃�8:30鈥斺€�11:00锛屽湪鍏垽涓€搴叕寮€瀹$悊锛氬啀瀹$敵璇�.. (2018-10-15) 路 2018骞�10鏈�16鏃�8: ...

  7. python 小数保留位数

    利用round(number[, ndigit] )函数四舍五入 保留浮点数的小数点. 如保留小数点后两位. num = 9.2174 new_num = round( num , 2 ) 则new_ ...

  8. java catch 捕获异常后会产生一个实例对象 该对象能使用父类的方法

  9. 51nod 1799 二分答案(分块打表)

    首先题目等价于求出满足运行二分程序后最后r=k的排列种数. 显然对于这样的二分程序,起作用的只有mid点,mid处的值决定了接下来要递归的子区间. 于是可以一遍二分求出有多少个mid点处的值<= ...

  10. 题解 P1334 【瑞瑞的木板】

    声明:本题解已经与其他题解重合, ### 且存在压行情况. 首先,这个题解是我有了惨痛的教训:全部WA... 先发一个CODE做声明: #include <bits/stdc++.h> / ...