hdu3519Lucky Coins Sequence

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
 

Recommend
zhengfeng

构造矩阵,运用矩阵快速幂即可。
构造矩阵是关键点,可先推导出递推式:设a[n]为长度为n的满足要求的方案数目,b[n]为长度为n的末尾最后两位不同的方案数字,c[n]为长度为n的末位相同的方案数。
那么有a[n]=c[n-1]+2a[n-1];b[n]=c[n-1]+b[n-1];c[n]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)]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值