递推求值
来源:互联网 发布:企业数据库视频教程 编辑:程序博客网 时间:2024/04/25 19:36
Covering
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 481 Accepted Submission(s): 226
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广西邀请赛-重现赛(感谢广西大学)
根据转移的状态列出来式子,可以把无用的状态去掉,注意式子一定不要漏掉,漏掉的话就gg,比直接推数据不知道高到哪里去了呢。
代码:
#include<stdio.h>#include<string.h>#define mod 1000000007#define N 6typedef long long LL;struct Matrix{ LL mat[N][N];};Matrix unit_matrix ={ 1, 0, 0,0,0,0, 0, 1, 0,0,0,0, 0, 0, 1,0,0,0, 0, 0, 0,1,0,0, 0, 0, 0,0,1,0, 0, 0, 0,0,0,1}; //单位矩阵Matrix mul(Matrix a, Matrix b) //矩阵相乘{ Matrix res; for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) { res.mat[i][j] = 0; for(int k = 0; k < N; k++) { res.mat[i][j] += a.mat[i][k] * b.mat[k][j]; res.mat[i][j] %= mod; } } return res;}Matrix pow_matrix(Matrix a, LL n) //矩阵快速幂{ Matrix res = unit_matrix; while(n != 0) { if(n & 1) res = mul(res, a); a = mul(a, a); n >>= 1; } return res;}int main(){ LL n; Matrix tmp, arr; while(scanf("%I64d",&n)!=EOF) {// scanf("%lld%lld%lld%lld%lld%lld",&f1, &f2, &a, &b, &c, &n); memset(arr.mat, 0, sizeof(arr.mat)); memset(tmp.mat, 0, sizeof(tmp.mat)); arr.mat[0][0] = 1; arr.mat[1][0] = 1; arr.mat[2][0] = 0; arr.mat[3][0] = 1; arr.mat[4][0] = 1; arr.mat[5][0] = 1; tmp.mat[0][5] = 1,tmp.mat[0][0]=1,tmp.mat[0][4] = 1,tmp.mat[0][1]=1,tmp.mat[0][3]=1; tmp.mat[1][0] = 1,tmp.mat[1][4]=1; tmp.mat[2][3]=1; tmp.mat[3][0]=1,tmp.mat[3][2]=1; tmp.mat[4][0]=1,tmp.mat[4][1]=1; tmp.mat[5][0]=1; tmp.mat[1][1] = tmp.mat[1][2] = tmp.mat[2][0] = tmp.mat[2][1] = 0; Matrix p = pow_matrix(tmp, n-1); p = mul(p, arr); LL ans = (p.mat[0][0] ) % mod; printf("%I64d\n",ans); }}
阅读全文
0 0
- acm-递推求值
- nyoj301 递推求值
- NYOJ301-递推求值
- 蓝桥杯 递推求值
- 递推求值
- 递推求值
- 蓝桥杯-递推求值
- nyoj301递推求值
- 递推求值
- 递推求值
- nyoj 301 递推求值
- Nyoj 301 递推求值
- NYOJ 301 递推求值
- ADV-218 递推求值
- NYISTME 1300 递推求值
- nyoj301递推求值【矩阵快速幂】
- nyoj301——递推求值
- nyoj 301 递推求值 矩阵幂
- Vue.js学习随笔
- 关于echart热力图 官网demo展示
- Struts2从一个action转到另一个action的两种方法
- 测试工具JMeter的安装及配置
- 深入解析iOS日志库CocoaLumberjack
- 递推求值
- 软件工程之概述
- SSH免密登录两台机器
- window下清除SVN文件
- jsp,jstl和el表达式的常用相关知识笔记
- UI排版中常用小技巧。
- 淘淘商城面试问题:----可能会被问到的问题
- 设计模式之桥接模式
- 集合的遍历