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)|
|