hdu6185 dp+矩阵乘法
来源:互联网 发布:签署淘宝图片空间协议 编辑:程序博客网 时间:2024/03/29 16:25
Covering
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)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广西邀请赛-重现赛(感谢广西大学)
老题新意
#include <string>#include <stdlib.h>#include <vector>#include <algorithm>#include <string.h>#include <stdio.h>#include <set>#include <iostream>#include <algorithm>#include <map>#include <queue>#include <math.h>#include<iostream>using namespace std;typedef long long LL ;const LL Mod = 1000000007 ;int a[16][16] ;void dfs(int n, int from, int to) { if(n > 4) return ; if(n == 4) { a[to][from] += 1 ; return ; } dfs(n+2, (from<<2)+3, (to<<2)+3) ; dfs(n+1, from<<1|1, (to<<1)) ; dfs(n+1, from<<1, to<<1|1 ) ;}struct Mat { LL v[16][16] ; Mat() { }; Mat(int c[16][16]) { for(int i = 0 ; i < 16 ; i++) { for(int j = 0 ; j < 16 ; j++) { v[i][j] = c[i][j] ; } } } Mat(int type) { memset(v, 0, sizeof(v)) ; if(type == 1) { for(int i = 0 ; i < 16 ; i++) { v[i][i] = 1 ; } } }};Mat mult(Mat x, Mat y) { Mat s = Mat(0) ; for(int k = 0 ; k < 16 ; k++) { for(int i = 0 ; i < 16 ; i++) { if(x.v[i][k] == 0) { continue ; } for(int j = 0 ; j < 16 ; j++) { s.v[i][j] += x.v[i][k] * y.v[k][j] ; s.v[i][j] %= Mod ; } } } return s ;}Mat pow(Mat x, LL y) { Mat s = Mat(1) ; for(; y > 0 ; y >>= 1) { if((y&1) > 0) { s = mult(s, x) ; } x = mult(x, x) ; } return s ;}int main() { memset(a, 0, sizeof(a)) ; dfs(0, 0, 0) ; LL n ; while(scanf("%I64d",&n) != EOF) { Mat A = Mat(a) ; A = pow(A, n) ; printf("%I64d\n", A.v[15][15]) ; } return 0 ;}
阅读全文
0 0
- hdu6185 dp+矩阵乘法
- 【区间DP】矩阵乘法
- 【DP】矩阵链乘法
- 矩阵乘法优化DP
- dp 最优矩阵乘法
- 矩阵乘法优化DP
- 【Contra】 矩阵乘法优化 dp
- 【bzoj3120】Line dp+矩阵乘法
- BZOJ 1009 DP+矩阵乘法
- 【DP】poj1651 <矩阵链乘法>
- bzoj 1875 矩阵乘法dp
- poj3744 概率dp+矩阵乘法
- 决战 dp+矩阵乘法+NTT
- 矩阵快速幂+高斯消元解递推方程-HDU6185
- HDU6185 Covering(矩阵快速幂)
- 【DP+压缩矩阵+矩阵乘法】阅读
- 程序碎片- 矩阵乘法优化(dp,递归)
- 程序碎片- 矩阵乘法优化(dp,循环)
- 基于XC7K325T FPGA 2路SRIO FMC 3U VPX板卡
- table()函数
- Python and与or
- overflow:hidden的原理问题
- Linux信号来源和捕获处理以及signal函数简介
- hdu6185 dp+矩阵乘法
- SpringBoot-RabbitMq 简单实例
- mongodb
- GitChat · 移动开发 | 小程序快速上手:三步完成小程序从无到有的开发
- J2SE相关笔记
- linux awk命令
- mybatis简单使用
- java中stringBuilder的用法
- Oracle 建立数据库,用户,表空间,数据导入