[HDU4652] Dice

Source: Internet
Author: User

Throw a dice with a M face, each face has a number, these numbers are different, for continuous throw to n the same number of the desired number of steps or the number of successive throw to n the number of expected steps

The same:

E[i] Indicates that there are already I consecutive the same, the desired number of steps to reach the target

e[i]=e[i+1]/m+ (1-1/m) e[1] ......... ..... 1

e[i+1]=e[i+2]/m+ (1-1/m) e[1] ......... 2

1-2 e[i]-e[i+1]= (e[i+1]+e[i+2])/m

Set S[i]=e[i]-e[i+1],

Then S[0]=e[0]-e[1]=1,s[i+1]=m*s[i],ans=sigma (S[i]) (0<=i<n)

Different:

E[i] Indicates that I have a continuous difference, the desired number of steps to reach the target

E[i]=simga (E[j])/m+ ((m-i)/m) e[i+1], (1<=j<=i) ....... 1

E[i+1]=sigma (E[j])/m+ ((m-i-1)/m) e[i+2], (1<=j<=i+1) .... 2

1-2 e[i]-e[i+1]= (m-i-1)/m* (e[i+1]-e[i+2])

Set S[i]=e[i]-e[i+1],

Then s[0]=e[0]-e[1]=1,s[i+1]=m/(m-i-1) S[i],ans=sigma (S[i]) (0<=i<n)

1#include <bits/stdc++.h>2 using namespacestd;3 #defineMAXN 10000054 intT,op,n;5 DoubleM,S[MAXN];6 voidsolve0 () {7s[0]=1;8     Doubleans=s[0];9      for(intI=0; i<n-1; i++)Tens[i+1]=s[i]*m,ans+=s[i+1]; Oneprintf"%.9lf\n", ans); A } - voidsolve1 () { -s[0]=1; the     Doubleans=s[0]; -      for(intI=0; i<n-1; i++) -s[i+1]=m/(m-i-1) *s[i],ans+=s[i+1]; -printf"%.9lf\n", ans); + } - intMain () { +scanf"%d",&T); A      while(t--){ atscanf"%d%lf%d",&op,&m,&n); -         if(op==0) solve0 (); -         Elsesolve1 (); -     } -     return 0; -}
View Code

  

[HDU4652] Dice

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.