HDU 6185Covering(矩阵快速幂)
来源:互联网 发布:人力资源系统 源码 编辑:程序博客网 时间:2024/06/07 15:52
Covering
Time Limit : 5000/2500ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 2 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Bob's school has a big playground, boys and girls always play games here after school.
To protect boys and girls from getting hurt when playing happily on the playground, rich boy Bob decided to cover the playground using his carpets.
Meanwhile, Bob is a mean boy, so he acquired that his carpets can not overlap one cell twice or more.
He has infinite carpets with sizes of1×2 and 2×1 , and the size of the playground is 4×n .
Can you tell Bob the total number of schemes where the carpets can cover the playground completely without overlapping?
To protect boys and girls from getting hurt when playing happily on the playground, rich boy Bob decided to cover the playground using his carpets.
Meanwhile, Bob is a mean boy, so he acquired that his carpets can not overlap one cell twice or more.
He has infinite carpets with sizes of
Can you tell Bob the total number of schemes where the carpets can cover the playground completely without overlapping?
Input
There are no more than 5000 test cases.
Each test case only contains one positive integer n in a line.
1≤n≤1018
Each test case only contains one positive integer n in a line.
Output
For each test cases, output the answer mod 1000000007 in a line.
Sample Input
12
Sample Output
15
Source
2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)
想法:
- 推导公式:F[i] = F[i-1] + 5*F[i-2] + F[i-3] - F[i-4]
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 4;const ll mod= 1e9+7;struct Matrix{ ll tmp[maxn][maxn];}a;void init(){ for(int i=0;i<maxn;i++) { for(int j=0;j<maxn;j++) { a.tmp[i][j]=0; } } a.tmp[0][0]=a.tmp[0][2]=1; a.tmp[0][1]=5; a.tmp[0][3]=-1; a.tmp[1][0]=a.tmp[2][1]=a.tmp[3][2]=1; return;}Matrix mul(Matrix a,Matrix b){ Matrix ans; for(int i=0;i<maxn;i++) for(int j=0;j<maxn;j++) { ans.tmp[i][j]=0; for(int k=0;k<maxn;k++) { ans.tmp[i][j]+=(a.tmp[i][k]*b.tmp[k][j]+mod)%mod; ans.tmp[i][j]%=mod; } } return ans;}void fun(Matrix ans,ll k){ for(int i=0;i<maxn;i++) { for(int j=0;j<maxn;j++) { a.tmp[i][j]=(i==j); } } while(k) { if(k%2) a=mul(a,ans); ans=mul(ans,ans); k/=2; } return ;}int main(){ Matrix t; ll n; for(int i=0;i<maxn;i++) { for(int j=0;j<maxn;j++) { t.tmp[i][j]=0; } } t.tmp[0][0]=36; t.tmp[1][0]=11; t.tmp[2][0]=5; t.tmp[3][0]=1; while(~scanf("%lld",&n)) { init(); if(n<=4) { printf("%lld\n",t.tmp[4-n][0]); continue; } fun(a,n-4); a=mul(a,t); printf("%lld\n",a.tmp[0][0]%mod); } return 0;}
阅读全文
0 0
- HDU 6185Covering(矩阵快速幂)
- hdu 6185 Covering(矩阵快速幂)
- HDU-6185 Covering(规律+矩阵快速幂)
- HDU 6185 && 2017广西邀请赛:Covering(矩阵快速幂)
- Hdu 6185 Covering【递推+矩阵快速幂】
- 【矩阵快速幂 && 状压dp】hdu-6185 Covering
- 【2017广西邀请赛】hdu 6185 Covering 矩阵快速幂
- HDU-6185-Covering(广西邀请赛D题)(矩阵快速幂)
- HDU 6185 Covering (2017 广西邀请赛重现赛)(矩阵快速幂)
- HDU6185 Covering(矩阵快速幂)
- hdu Covering 2017广西邀请赛 矩阵快速幂
- 2017 ACM/ICPC 广西邀请赛||HDU 6185 Covering 【状压DP+矩阵快速幂】
- 2017广西邀请赛 Covering(矩阵快速幂)
- hdu6185 Covering (递推+矩阵快速幂)
- 2017广西邀请赛 D题Covering (递推+矩阵快速幂)
- hdu 6185 Covering
- HDU 6185 Covering
- 解题报告:HDU_6185 Covering (轮廓线DP+高斯消元+矩阵快速幂)
- tomcat并发与线程数
- Xcode9配置Git操作
- 1.3多媒体存储技术
- Android 项目混淆
- ubuntu 16.04 安装docker、docker-compose
- HDU 6185Covering(矩阵快速幂)
- excel
- centos-6.5-x64搭建hadoop集群
- jdk1.7DualPivotQuicksort
- selenium 各版本简介及相关特性
- 计蒜客 16956 Query on a string(2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 G)
- 欢迎使用CSDN-markdown编辑器
- HTML-后台管理模版
- poj1018 Communication System