Light OJ 1317 throwing Balls into the baskets probability DP

Source: Internet
Author: User

N individual m baskets each round each one can choose M basket in the probability of throwing a ball in the throw is p to find the number of balls in all baskets after the K-wheel value

The expected number of balls based on the full expectation formula is dp[1]*1+dp[2]*2+...+dp[n]*n as W

Where Dp[i] is the probability of a person throwing in dp[i] = C (n, i) *p^i* (1-p) ^ (n-i) The final answer is W*k

#include <cstdio> #include <cstring>using namespace std;double dp[20];d ouble a[20], b[20];d ouble cm (int n, int m) {Double ans = 1;for (int i = 1; I <= m; i++) {ans *= (double) N--;ans/= (double) I;} return ans;} int main () {int t;int cas = 1;scanf ("%d", &t), while (t--) {int n, m, k;double p;scanf ("%d%d%d%lf", &n, &m, &am P;k, &p);DP [0] = a[0] = b[0] = 1;for (int i = 1; I <= n; i++) {a[i] = a[i-1]*p;b[i] = b[i-1]* (1-p);} for (int i = 0; I <= N; i++) {Dp[i] = cm (n, i) *a[i]*b[n-i];} Double ans = 0;for (int i = 1; I <= n; i++) ans + dp[i]* (double) I;ans *= (double) k;printf ("Case%d:%.10lf\n", cas++, an s);} return 0;}



Light OJ 1317 throwing Balls into the baskets probability DP

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.