SGU 495 Kids and prizes

Source: Internet
Author: User
Tags cmath

Mathematical Methods:

    • From each box to consider: After M-selection, at least once the probability of being selected. Because these boxes are independent of each other, the number of boxes selected is expected to be
1#include <iostream>2#include <cmath>3#include <cstdio>4 using namespacestd;5 6 intMain ()7 {8     intN, M;9      while(SCANF ("%d%d", &n, &m) = =2)Ten     { One         DoubleAns = n *1.0* (1.0-Pow ((1.0- (1.0/N)), (m)); Aprintf"%.12f\n", ans); -     } -  the     return 0; -}
code June

Dp:

    • can also be considered from the person, set D (i) for the first person to win the probability of winning, then

      If the i-1 person does not win the prize, then the first person to win and the first i-1 the probability of winning is the same;

      If the i-1 individual wins, then the probability of the first person to win will be less than the probability of the first i-1 individual winning 1/n.

      So d (i) = d (i-1) * (d (i-1)-1/n) + (1-d (i-1)) * d (i-1)

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cmath>6 using namespacestd;7 Const intmaxn=110000;8 DoubleDP[MAXN];9 intMain ()Ten { One     Doublen,m; A      while(SCANF ("%LF%LF", &n,&m) = =2) -     { -         Doublesum=1.0; thedp[1]=1; -          for(intI=2; i<=m;i++) -         { -Dp[i]= (1-dp[i-1]) *dp[i-1]+dp[i-1]* (dp[i-1]-1.0/n); +sum+=Dp[i]; -         } +printf"%.9f\n", sum); A     } at     return 0; -}
code June

SGU 495 Kids and prizes

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.