DNA "description"
A kind of virus has attacked the X planet, and many lives is infected. After weeks of study, the CHO (Creature Healthy Organization) of X Planet finally finds out that this kind of virus have TW O kind of very simple DNA, and can is represented by 101 and 111. Unfortunately, the lives on the planet also has DNA formed by 0s and 1s. If a creature ' s DNA contains the virus ' DNA, it'll be affected; Otherwise it would not. Given an integer l, it's clear that there'll be 2 ^ L different lives, of which the length of DNA is L. Your job is-find out in the 2 ^ L lives how many won ' t be affected?
Input
The input contains several test cases. For each test case it contains a positive integer l (1 <= L <= 10 ^ 6). The end of input is indicated by End-of-file.
Output
For each test case, the output K mod 2005, here K was the number of lives that would not be affected.
"Sample Input"
4
"Sample Output"
9
"Solution"
According to test instructions, 111, 101 is not legal, so we
Make F1[i] for the length of I and end three numbers is all valid 01 strings of the number,
Order F2[i] for the length of I and the end of the three numbers are all valid 01 strings of the 001 ,
Order F3[i] for the length of I and the end of the three numbers are all valid 01 strings of the 010 ,
Order F4[i] for the length of I and the end of the three numbers are all valid 01 strings of the 011 ,
Order F5[i] for the length of I and end three numbers is all valid 01 strings of
Make F6[i] for the length of I and end three numbers are all valid 01 strings of the number of a.
The current length is n. We found that 000 of the last two bits, 100 of the next two bits and F1[n] The final three bits of the first two bits are equal, and the more one there are two cases 0 and 1, choose to conform to F1[n] the last one on the line, the program number is unchanged, so that the last three bits f1[n], f1[n] can be from f1[n-1] and f5[n-1] transfer. So f1[n]=f1[n-1]+f5[n-1].
And so on
F2[N]=F1[N-1]+F5[N-1]
f3[n] =f2[n-1]
F4[N]=F2[N-1]
F5[N]=F3[N-1]+F6[N-1]
F6[N]=F4[N-1]
Make Dp[n]=f1[n]+f2[n]+f3[n]+f4[n]+f5[n]+f6[n]. The following is the mathematical derivation of the Chi (odd) (skill) human (kinky) Heart (artful):
Dp[n]=f1[n]+f2[n]+f3[n]+f4[n]+f5[n]+f6[n]
=F1[N-1]+F5[N-1]+F1[N-1]+F5[N-1]+F2[N-1]+F2[N-1]+F3[N-1]+F6[N-1]+F4[N-1]
=dp[n-1]+f3[n-2]+f6[n-2]+f1[n-2]+f5[n-2]+f1[n-2]+f5[n-2]
=dp[n-1]+f2[n-3]+f4[n-3]+f1[n-3]+f5[n-3]+f3[n-3]+f6[n-3]+f1[n-3]+f5[n-3]+f3[n-3]+f6[n-3]
=dp[n-1]+dp[n-3]+f1[n-3]+f5[n-3]+f3[n-3]+f6[n-3]
=DP[N-1]+DP[N-3]+F1[N-4]+F5[N-4]+F3[N-4]+F6[N-4]+F2[N-4]+F4[N-4]
=DP[N-1]+DP[N-3]+DP[N-4]
1#include <cstdio>2 intN;3 intdp[1000010];4 intMain () {5scanf"%d", &n); dp[1]=2; dp[2]=4;DP [3]=6; dp[4]=9;6 for(intI=5; i<=n;++i) dp[i]= (dp[i-1]%2005+dp[i-3]%2005+dp[i-4]%2005)%2005;7printf"%d", Dp[n]);8 return 0;9}
"OpenJudge9270" "Pku2440" "Recursive" DNA