hdu3519Lucky Coins Sequence
2016-07-11 09:53
603 查看
Lucky Coins Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 912 Accepted Submission(s): 481
Problem Description
As we all know,every coin has two sides,with one side facing up and another side facing down.Now,We consider two coins's state is same if they both facing up or down.If we have N coins and put them in a line,all of us know that it will be 2^N different ways.We
call a "N coins sequence" as a Lucky Coins Sequence only if there exists more than two continuous coins's state are same.How many different Lucky Coins Sequences exist?
Input
There will be sevaral test cases.For each test case,the first line is only a positive integer n,which means n coins put in a line.Also,n not exceed 10^9.
Output
You should output the ways of lucky coins sequences exist with n coins ,but the answer will be very large,so you just output the answer module 10007.
Sample Input
3
4
Sample Output
2
6
Source
2010 ACM-ICPC Multi-University
Training Contest(9)——Host by HNU
Recommend
zhengfeng
构造矩阵,运用矩阵快速幂即可。
构造矩阵是关键点,可先推导出递推式:设a
为长度为n的满足要求的方案数目,b
为长度为n的末尾最后两位不同的方案数字,c
为长度为n的末位相同的方案数。
那么有a
=c[n-1]+2a[n-1];b
=c[n-1]+b[n-1];c
b[n-1];
可知
[2,0,1] [a(n-1)] [a(n)][0,1,1] * [b(n-1)] = [b(n)][0,1,0] [C(n-1)] [C(n)]
相关文章推荐
- IOS build 与version,InfoDictionary version的区别
- 应用Druid监控SQL语句的执行情况(测试数据表明,Druid性能比DBCP、C3P0、Proxool、JBoss都好)
- Web自动化框架LazyUI使用手册(3)--单个xpath抓取插件详解(selenium元素抓取,有此插件,便再无所求!)
- Web自动化框架LazyUI使用手册(3)--单个xpath抓取插件详解(selenium元素抓取,有此插件,便再无所求!)
- DUKPT(derived unique key per Transaction)
- 文件和目录之stat族函数<stat | fstat | lstat | fstatat>——APUE学习笔记(2)
- UITextView的placehoder实现带并限制100字
- ansible操作远程服务器报Error: ansible requires the stdlib json or simplejson module, neither was found!
- 2016-07-11 Null value was assigned to a property of primitive type setter 问题
- Android UI设计之<十二>自定义View,实现绚丽的字体大小控制控件FontSliderBar
- 在 PC 端使用Bluemix的 Internet of Things Foundation 双向传达接收远程装置信息
- 强大的在线web编辑器UEditor
- B - Ubiquitous Religions
- 3990 G. I guess the gift is a bag! II
- 3985. I guess the gift is a bag!
- @RequestParam 的用法
- String StringBuffer StringBuilder 区别
- Uncaught TypeError: ((n.event.special[g.origType] || (intermediate value)).handle || g.handler)....
- Android : UI Layout
- Longest Consecutive Sequence