Title: The n Dice on the floor. All points of the dice on the upward side and one s. Enter n, the probability of printing s all possible values.
Statement ideas are not original! Just because the use of dynamic planning ideas is very good, write down.
Analysis: Dynamic planning is a phased consideration of issues. Give the variable. Find the relationship between adjacent phases. A detailed definition to forget.
1. Now the variables are: Dice number, points and.
When there is a K-dice. Points and is n. The number of occurrences is recorded as F (k,n). What is the relationship between that and the k-1 dice phase?
2. When I have k-1 a dice. Add another dice, the dice can only be 1, 2, 3, 4, 5 or 6. The case that K dice get points and for N is:
(k-1,n-1): K Dice Cast points 1
(k-1,n-2): K Dice Cast points 2
(k-1,n-3): K Dice Cast points 3
....
(k-1,n-6): K Dice Cast points 6
On the basis of k-1 dice, adding a dice to the number of points and the result of n is only 6 cases.
So:f (k,n) =f (k-1,n-1) +f (k-1,n-2) +f (k-1,n-3) +f (k-1,n-4) +f (k-1,n-5) +f (k-1,n-6)
3. There are 1 dice, f (=f) =f (1,3) =f (1,4) =f (1,5) =f (1,6) = 1.
The code is easy to write, recursive functions, returns, and the number of occurrences of N. Total sum of occurrences is 6^n.
http://zhedahht.blog.163.com/blog/#m =0
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
n probability of each count and occurrence of dice--dynamic planning