博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2017ACM/ICPC广西邀请赛 1004 Covering
阅读量:7042 次
发布时间:2019-06-28

本文共 2203 字,大约阅读时间需要 7 分钟。

Covering

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 0    Accepted Submission(s): 0

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 of
1×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?
 

 

Input
There are no more than 5000 test cases.
Each test case only contains one positive integer n in a line.
1n1018
 

 

Output
For each test cases, output the answer mod 1000000007 in a line.
 

 

Sample Input
1 2
 

 

Sample Output
1 5
题解:这个题目不是很好写  ,但是有很多人AC得特别快   大神的脚步完全跟不上
直接找规律    想公式  想了特别就都没有想出来
还是实验室有人使用dfs求了前面几个数的答案   然后使用循环求出去套出了规律
不过找到了规律  数据量也还是很大    10的18次方  
所以这里还是得使用矩阵快速幂    才行
1 矩阵的算法   比赛中比较常见 2 #include 
3 #include
4 #include
5 #include
6 #include
7 #define ll long long 8 using namespace std; 9 const int maxn = 4;10 ll Matrixsize = 4, mod = int(1e9)+7, n;11 struct Matrix {12 ll m[maxn][maxn];13 Matrix(ll i = 0) {14 memset(m, 0, sizeof m);15 if (i == 1)16 for (ll I = 0; I < Matrixsize; I++) m[I][I] = 1;17 }18 Matrix operator * (const Matrix tmp) const {19 Matrix ret;20 long long x;21 for(ll i=0 ; i
0) {33 if (bool(n & 1)) ret = ret * tmp;34 tmp = tmp * tmp;35 n >>= 1;36 }37 return ret;38 }39 };40 41 int main() {42 Matrix base1 = 0, base2 = 0;43 base1.m[0][0] = base1.m[0][2] = base1.m[1][0] = base1.m[2][1] = base1.m[3][2] = 1;44 base1.m[0][3] = -1, base1.m[0][1] = 5, base2.m[0][0] = 1;45 base2.m[1][0] = 0, base2.m[2][0] = 1, base2.m[3][0] = 1;46 while(~scanf("%lld",&n)) printf("%lld\n",(base1.qpow(n)*base2).m[0][0]);47 return 0;48 }

 

转载于:https://www.cnblogs.com/52why/p/7460014.html

你可能感兴趣的文章
微信web开发遇到的坑
查看>>
写了一个数字转成简 / 繁体汉字的助手函数
查看>>
vue配合iview/element等ui实现界面效果起步
查看>>
仿饿了么项目-vue的学习笔记总目录
查看>>
Angular 2.x+ 如何动态装载组件
查看>>
React中的setTimeout、setInterval的注意事项
查看>>
如何深入使用scss开发一个简单页面
查看>>
JS学习系列 03 - 函数作用域和块作用域
查看>>
外卖订单爬虫(美团,饿了么,百度外卖)
查看>>
用Flink取代Spark Streaming,知乎实时数仓架构演进
查看>>
2019年值得关注的八大DevOps趋势
查看>>
教育部下令中小学推广编程教育,全民AI真的要来了
查看>>
C#未来新特性:静态委托和函数指针
查看>>
从Python2到Python3:超百万行代码迁移实践
查看>>
如何避免移动测试自动化失败
查看>>
Real World Kanban作者访谈
查看>>
Confluent平台5.0支持LDAP授权及用于IoT集成的MQTT代理
查看>>
Promise 源码分析
查看>>
干货 :手把手教你在试验中修正机器学习模型
查看>>
.NET Core2.1下采用EFCore比较原生IOC、AspectCore、AutoFac之间的性能 ...
查看>>