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. struts常量<constant>说明

    1.<constant name="struts.action.extension" value="do" />这个时候访问action都必须加.d ...

  2. VS2015做单元测试

    1.安装测试插件 2.新建测试用例 这里就用课堂练习找水王  作例子 写一个类waterKing.h和waterKing.cpp //idList.h #pragma once #include< ...

  3. lintcode-129-重哈希

    129-重哈希 哈希表容量的大小在一开始是不确定的.如果哈希表存储的元素太多(如超过容量的十分之一),我们应该将哈希表容量扩大一倍,并将所有的哈希值重新安排.假设你有如下一哈希表: size=3, c ...

  4. 软工实践团队展示——WorldElite

    软工实践团队展示--WorldElite 本次作业链接 团队成员 031602636许舒玲(组长) 031602237吴杰婷 031602634吴志鸿 081600107傅滨 031602220雷博浩 ...

  5. 小程序获取access_token

    <?php //小程序appid $appid = 'wx79d7c348d19f010c'; //小程序 APPSecret 密钥 $appsecret = 'd624aca86d0350ee ...

  6. win7仿win98电脑主题

    http://ys-d.ys168.com/599631823/S7hMfgo3M382J764IOJ8/plus98_for_windows_7_by_ansonsterling.zip

  7. vue.cli实现tab切换效果

    <template> <div class="cp-select">                     <div class="lef ...

  8. 第103天:CSS3中Flex布局(伸缩布局)详解

    一.Flex布局 Flex是Flexible Box的缩写,意为”弹性布局”,用来为盒状模型提供最大的灵活性. 任何一个容器都可以指定为Flex布局. .box{ display: flex; } 行 ...

  9. HDU4054_Hexadecimal View

    水题.直接八位八位地枚举即可. 注意控制输出,注意读数的时候要把s中的全部元素置零. #include <iostream> #include <cstdio> #includ ...

  10. Django 2.0 学习(17):Django 用户认证(auth模块)

    Django 用户认证(auth模块) 一.认证登陆 在进行用户登陆验证的时候,如果是自己写代码,就必须要先查询数据库,看用户输入的用户名是否存在于数据库中:如果用户存在于数据库中,然后再验证用户输入 ...