Portal: Random Fibonacci
#1164: Random Fibonacci Time limit:5000msSingle Point time limit:1000msMemory Limit:256MBDescribe
You must be familiar with the Fibonacci sequence:
a0 = 1, a1 = 1, ai = ai-1 + ai-2, (i > 1).
Now consider the following generated Fibonacci sequence:
a0 = 1, ai = AJ + ak, i > 0, J, K are randomly selected from integers [0, I-1] (independent of J and K).
Now given n, it is required to find E (an), that is, the expected value of an in various possible a sequences.
Input
An integer n of one line representing the nth item. (1<=n<=500)
Output
A real number on a line that represents the answer. The absolute or relative error of your output and answer is considered the correct answer if it is less than 10-6.
Sample explanation
Coexistence in 3 possible sequences
1,2,2 1/4
1/2
1,2,4 1/4
Therefore the expectation is 3.
-
Sample input
-
2
-
Sample output
-
3.000000
Analysis: This problem should pay special attention to J and K Independent of this condition, under which we can get E (an) (hereinafter abbreviated to E[N]) an expression
E[n] = 2*s[n-1]/n,
Where SN is defined as
S[n] = e[0] + e[1] + e[2] + .... + E[n]
I'll start with the two formulas above to launch e[n] about n expressions.
By
E[n] = S[n]-s[n-1]
And
E[n] = 2 * S[n-1]/n
Eliminate s[n] to get
E[n] = 2 * S[n-1]/n
That
n * E[n] = 2 * s[n-1]
Thus there are also
(n+1) * E[n+1] = 2 * S[n]
Combine the above two and the first type to get
(n+1) * E[n+1]-n * e[n] = 2 * E[n]
i.e.
E[N+1]/e[n] = (n+2)/(n+1)
And then get
E[n] = (n+1) e[0] = n+1
Hihocoder 1164 Random Fibonacci