Lucky Coins Sequence |
| Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) |
| Total Submission(s): 46 Accepted Submission(s): 32 |
|
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
这个题的线性方程就没有那么直白了,需要推导一下。
设a(n)为 长度为n的,Lucky Coins Sequences的个数
设 f(n)为长度为n的,连续face相同个数小于三的情况(2^n - f(n) == a(n))
若f(n)的后两位相同 则f(n)=f(n-2); 即在f(n-2)后面加上00或者11; 若f(n-1)的后两位不同 则f(n)=f(n-1) 即在f(n-1)后面加上0或者1; 因此可得f(n)=f(n-1)+f(n-2); 所以 2^n - f(n) == 2 ^ (n-1) - f(n-1) + 2 ^ (n-2) - f(n-2) + 2 ^ (n-2) -----> a(n) = a(n-1) + a(n-2) + 2^(n-2); 构造矩阵:| a(n) | | 1 1 1 | | a(4). | | a(n-1) | * | 1 0 0 | ^ (n-4) = | a(3) | |2^(n-1)| | 0 0 2 | | 2^(n-2)|
|
Lucky Coins Sequence (矩阵快速幂)
本文探讨了一种特殊的硬币序列——幸运硬币序列,并通过矩阵快速幂算法求解其数量。具体而言,针对给定数量的硬币,计算所有可能的排列中,至少存在三个连续相同状态的硬币序列的数量。
&spm=1001.2101.3001.5002&articleId=72790750&d=1&t=3&u=340da85304ba4c968fb0eca65d082274)
272

被折叠的 条评论
为什么被折叠?



