<题目链接>

<转载于 >>> >

题目大意:

让你用1*2规格的地毯去铺4*n规格的地面,告诉你n,问有多少种不同的方案使得地面恰好被铺满且地毯不重叠。答案对1000000007取模。

解题分析:

看到题目所给n的数据这么大,就知道肯定存在递推公式,至于递推公式的具体的分析过程  >>>大牛博客。求出递推公式后,由于数据太大,所以我们利用矩阵快速幂来加速。当然,如果比赛的时候想不到递推公式,我们也可以通过搜素得到前面的几组数据,然后在通过高斯消元来得到符合这些数据的公式的通解,最后再利用矩阵快速幂来求解。

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
#define LL long long
const int mod=;
struct matrix
{
LL x[][];
};
matrix mutimatrix(matrix a,matrix b)
{
matrix temp;
memset(temp.x,,sizeof(temp.x));
for(int i=;i<;i++)
for(int j=;j<;j++)
for(int k=;k<;k++)
{
temp.x[i][j]+=a.x[i][k]*b.x[k][j];
temp.x[i][j]%=mod;
}
return temp;
} matrix k_powmatrix(matrix a,LL n)//矩阵快速幂
{
matrix temp;
memset(temp.x,,sizeof(temp.x));
for(int i=;i<;i++)
temp.x[i][i]=; while(n)
{
if(n&)
temp=mutimatrix(temp,a); a=mutimatrix(a,a);
n>>=;
}
return temp;
} int main()
{
LL n;
while(scanf("%lld",&n)!=EOF)
{
//前面四个手算下
if(n==)
{
printf("1\n");
continue;
}
if(n==)
{
printf("5\n");
continue;
}
if(n==)
{
printf("11\n");
continue;
}
if(n==)
{
printf("36\n");
continue;
} matrix st;
memset(st.x,,sizeof(st.x));
st.x[][]=;
st.x[][]=;
st.x[][]=;
st.x[][]=-; st.x[][]=;
st.x[][]=;
st.x[][]=; matrix init;//初始矩阵
memset(init.x,,sizeof(init.x)); init.x[][]=;
init.x[][]=;
init.x[][]=;
init.x[][]=; st=k_powmatrix(st,n-);//经过n-4次相乘
st=mutimatrix(init,st);//然后再乘上初始矩阵 printf("%lld\n",(st.x[][]+mod)%mod);
}
return ;
}

2018-08-09

hdu 6185 递推+【矩阵快速幂】的更多相关文章

  1. hdu 6185 递推+矩阵快速幂

    思路:考虑全部铺满时,前2列的放法.有如下5种情况:(转自http://blog.csdn.net/elbadaernu/article/details/77825979 写的很详细 膜一下)  假设 ...

  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. HDU Queuing(递推+矩阵快速幂)

    Queuing Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

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

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

  7. HDU - 6185 Covering(暴搜+递推+矩阵快速幂)

    Covering Bob's school has a big playground, boys and girls always play games here after school. To p ...

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

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

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

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

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

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

随机推荐

  1. 5、利用两个栈实现队列,完成push和pop操作

    题目描述 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 思路: 1.一个栈用来做push 2.另一个栈用来做pop 3.将push操作的栈的元素放入另一个栈中, ...

  2. 【比赛游记】NOIP2018游记

    往期回顾:[比赛游记]NOIP2017游记 转眼间又过去了一年,当年还是初中生的我已经摇身一变成为了AHSOFNU的高一学生. 回顾这一年我好像也没学什么新东西,要说有用的可能就无旋Treap吧,不知 ...

  3. python模块分析之logging日志(四)

    前言 python的logging模块是用来设置日志的,是python的标准模块. 系列文章 python模块分析之random(一) python模块分析之hashlib加密(二) python模块 ...

  4. freeRTOS中文实用教程6--错误排查

    1.前言 本章主要是为刚接触FreeRTOS 的用户指出那些新手通常容易遇到的问题.这里把最主要的篇幅放在栈溢出以及栈溢出侦测上 2.printf-stdarg.c 当调用标准C 库函数时,栈空间使用 ...

  5. DDR3基本知识及测试【转】

    转自:http://blog.csdn.net/myarrow/article/details/7847385 一.DDR3简介 DDR3(double-data-rate three synchro ...

  6. uboot中的快捷菜单的制作说明 【转】

    转自:http://blog.chinaunix.net/uid-22030783-id-366971.html   在uboot中加入快捷操作菜单的方法非常简单,在论坛发布的uboot201003V ...

  7. WPF通过DynamicResource的用法

    1.先在资源类库中编写:style.xaml,如下: <ResourceDictionary   xmlns="http://schemas.microsoft.com/winfx/2 ...

  8. HTML表格的简单使用1

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. freerradius 错误:pap: WARNING: No "known good" password found for the user

    具体错误如下: 1) # Executing section authorize from file /usr/local/etc/raddb/sites-enabled/default(1)   a ...

  10. MySQL 数据类型(转)

    MySQL 数据类型 在 MySQL 中,有三种主要的类型:文本.数字和日期/时间类型. Text 类型: 数据类型 描述 备注 CHAR(size) 保存固定长度的字符串(可包含字母.数字以及特殊字 ...