Hdu 4562 Dice calculate the expected mathematical formula

Source: Internet
Author: User

The state transition equation for this question should be very good. If the equation cannot be pushed, you don't have to worry about it. You just need to do more to find the expected question.

 


If dp [I] is set, it indicates the number of throws that are expected to be throttled when I have been thrown in a different or the same status. Then dp [0] is the answer

 

 

The same situation:
Dp [0] = 1 + dp [1]
Dp [1] = 1 + (m-1) * dp [1] + dp [2])/m
Dp [I] = 1 + (m-1) * dp [1] + dp [I + 1])/m
...
Dp [n] = 0;


Let's take out the I and I + items.
Dp [I] = 1 + (m-1) * dp [1] + dp [I + 1])/m
Dp [I + 1] = 1 + (m-1) * dp [1] + dp [I + 2])/m


Offset: m * (dp [I]-dp [I + 1]) = dp [I + 1]-dp [I + 2];


If d [I] = dp [I]-dp [I + 1] is set, d [] is an proportional sequence with a common ratio of m, and d [0] = 1;


So d [I] = m ^ I, and then dp [0]-dp [I + 1] = m ^ 0 + m ^ 1 + ..... + m ^ I;


If I + 1 = n, dp [0] = m ^ 0 + m ^ 1 +... + m ^ (n-1 );

 

 


Different situations:
Dp [0] = 1 + dp [1]
Dp [1] = 1 + (dp [1] + m-1) dp [2])/m
Dp [2] = 1 + (dp [1] + dp [2] + (m-2) dp [3])/m
Dp [I] = 1 + (dp [1] + dp [2] +... dp [I] + (m-I) * dp [I + 1])/m
...
Dp [n] = 0;

In the same case, select dp [I] and dp [I + 1] to subtract

Dp [I]-dp [I + 1] = (m-i-1)/m * (dp [I + 1]-dp [I + 2]);

D [I] = dp [I]-dp [I + 1]. then d [I] = (m-i-1)/m * d [I + 1], and d [0] = 1;

This formula looks similar to the same, but it cannot be simplified.

However, we can find every d [I] based on this recursive relationship.


Then, when the column items are eliminated, we can find that dp [0] = d [0] + d [1] + d [2] + ...... + d [n-1];

 

Using these two formulas, the code can be AC very short, so the code is not given

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.