NOIP2013 improve problem solving T2 (on recursive and recursive)

Synchronization published in my Luogu Bo off.

NOIP2013 improve problem solving 2:

Prior frog, initially on a lotus leaf number n. When the number k lotus leaf, the next time it will be a time equal probability of random jumps to 1, ......, k-th one of the leaf, until the far jump No. 1 lotus leaf. When n = 2, mean total jump twice, while 3 n =, the average total of 2.5 hops. When n is equal to 5, the average total jump a few times.

First question into a frog jumped random situation after step, is divided into five cases, which are falling No. 1, No. 2, No. 3, No. 4, No. 5 lotus leaf. The probability of occurrence of each case 1/5.

Then set f (n) is the desired average number n lotus leaf sheet. Obviously, f (1) = 1.

Start with a simple consideration:

当n=2:
共2种情况:落在1号或2号上。
落在1号上,问题变为求f(1)。
落在2号上,问题变为求f(2)+1。

Q: Why plus 1?
A: Because it has skipped once.

Q: Why does f (1) do not?
A: Because it has come to.

Because it is averaged, and f (1) is known, the equation can be listed:

f(2)=(f(1)+1+f(2))*1/2

Solve for f (2) = 2.

Q: Why should all added?
A: Please consider the addition principle.

Then to the state of n = 3:

共3种情况:落在1号或2号或3号上。
落在1号上,问题变为求f(1)。
落在2号上,问题变为求f(2)+1。
落在3号上,问题变为求f(3)+1。

Cooked unfamiliar?

Each of the original problem can be divided into n sub-problems, the scale becomes smaller sub-problems (???), sub-problems can be obtained by adding the original questions.

Feeling a bit recursive.

Expanded to look at the state of n = k:

共k种情况:落在1号或2号或3号或……或k号上。
落在1号上,问题变为求f(1)。
落在2号上,问题变为求f(2)+1。
落在3号上,问题变为求f(3)+1。
……
此处省略
……
落在k号上,问题变为求f(k)+1。

Available equation f (k) = (f (1) + 1 + f (2) + 1 + f (3) + ······ + 1 + f (k)) * 1 / k

Next, the above equation merger of similar items:

k*f(k)=(f(1)+1+f(2)+1+f(3)+······+1+f(k))

k*f(k)=k-1+(f(1)+f(2)+f(3)+······+f(k))

(k-1)*f(k)=k-1+(f(1)+f(2)+f(3)+······+f(k-1))

f(k)=1+(f(1)+f(2)+f(3)+······+f(k-1))*1/k

At this point, f (n) recurrence formula was introduced us:

f(n)=1+(f(1)+..f(n-1))/(n-1)

The difficulty of solving the problem also lies in the introduction of recurrence formula, the introduction of recurrence formula, n = 5 horse God, is slag slag.

Well, now, to a summary: First, let's use recursive thinking to try to reduce the size of the problem, after downsizing, you can list the relationship. After again from general to specific, list relationship in general, simplification, we found that the form of expression of the simplification of the form recursive, then we can be solved from the bottom up.

In fact, sometimes recursive and recursive essentially, no difference. Sometimes we use a recursive thought to consider the issue, with a recursive way to achieve solving, which can greatly reduce the difficulty thinking and code implementation difficult.

As for why recursive and recursive essentially, no difference. First of all have to figure out that this is a problem for the use of recursive solving.

Because any recursive loop can be used to write (as long as your gall bladder is large enough, not afraid of burst 0), we realize the general recursive loop is nothing more than an array of like a +. Therefore, the recursive will be able to use recursion to achieve. For example, Fibonacci number. (Think of dynamic programming it, dfs nothing more than increase the complexity of it) but please note that not all recursive loop can be used to achieve drops, for example, backtracking. So, it can be drawn: recursion recursion can not necessarily be achieved.

I hope you can help, even a little bit, and I meet.
Be reproduced, please indicate the author and source.

Guess you like

Origin www.cnblogs.com/zhukaiyuan/p/11610329.html