Light OJ 1248-dice (III) probability DP

Source: Internet
Author: User

N-sided dice ask for the expectation that each face is thrown at least once

Set Dp[i] for the expectation that I have been thrown on different faces dp[n] = 0 for dp[0]

Because Dp[i] is also required to throw a different face each time it may throw the face that has been thrown or has not been thrown over the face of the situation 2

So dp[i] = (i/n) *dp[i] + (n-i)/n*dp[i+1] +1 equals 2 sides have dp[i]

Move term dp[i] = dp[i+1]+n/(n-i)

#include <cstdio>
#include <cstring>
#define IMAX 100005
double Dp[imax];
int n;
int main ()
{
	int t,tt;
	scanf ("%d", &t);
	for (tt=1;tt<=t;tt++)
	{
		scanf ("%d", &n);
		dp[n]=0;
		for (int i=n-1;i>=0;i--)
		{
			dp[i]=dp[i+1]+ (double) n/(n-i);
		}
		printf ("Case%d:%.8lf\n", tt,dp[0]);
	}
	return 0;
}



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.