LightOJ - 1317 Throwing Balls into the Baskets 期望

题目大意:有N个人,M个篮框,K个回合,每个回合每个人可以投一颗球,每个人的命中率都是相同的P,问K回合后,投中的球的期望数是多少

解题思路:因为每个人的投篮都是一个独立的事件,互不影响,所以每回合投中的球的期望数是相同的

只需求得一回合的期望再乘上K就答案了

#include<cstdio>
#define maxn 100
double ans, p;
int n, m, k;
int c[20][20];

void init() {
    c[1][1] = c[1][0] = 1;
    for(int i = 2; i < 20; i++) {
        c[i][i] = c[i][0] = 1;
        for(int j = 1; j < i; j++)
            c[i][j] = c[i-1][j] + c[i-1][j-1];
    }
}

double count(int j) {
    double t = 1.0;
    for(int i = 0; i < j; i++)
        t *= p;

    for(int i = 0; i < n - j; i++)
        t *= (1.0 - p);

    return t * j * c[n][j];
}

int main() {
    int test, cas = 1;
    scanf("%d", &test);
    init();
    while(test--) {
        scanf("%d%d%d%lf", &n, &m, &k, &p);
        ans = 0.0;
        for(int i = 0; i <= n; i++)
            ans += count(i);

        printf("Case %d: %.7lf\n", cas++ ,ans * k);
    }
    return 0;
}
时间: 2024-10-22 05:24:01

LightOJ - 1317 Throwing Balls into the Baskets 期望的相关文章

lightOJ 1317 Throwing Balls into the Baskets

lightOJ  1317  Throwing Balls into the Baskets(期望)  解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88890#problem/A 题目: Description You probably have played the game "Throwing Balls into the Basket". It is a simple game. You have

Light OJ 1317 Throwing Balls into the Baskets 概率DP

?n个人 m个篮子 每一轮每一个人能够选m个篮子中一个扔球 扔中的概率都是p 求k轮后全部篮子里面球数量的期望值 依据全期望公式 进行一轮球数量的期望值为dp[1]*1+dp[2]*2+...+dp[n]*n 记为w 当中dp[i]为i个人扔中的概率 dp[i] = C(n, i)*p^i*(1-p)^(n-i) 终于答案为w*k #include <cstdio> #include <cstring> using namespace std; double dp[20]; dou

LightOj_1317 Throwing Balls into the Baskets

题目链接 题意: 有N个人, M个篮框, 每个人投进球的概率是P. 问每个人投K次后, 进球数的期望. 思路: 每个人都是相互独立的, 求出一个人进球数的期望即可. 进球数和篮框的选择貌似没有什么关系, 所以给的这个M并没有什么卵用.... 每个人进球数的期望为:E = sigma (i * C(K, i) * p ^ i * (1 - p) ^ (k - i)); 总的进球数期望为:N * E 代码: 1 #include <cmath> 2 #include <cstdio>

LightOJ 1317 第六周比赛A题

A - A Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Description You probably have played the game "Throwing Balls into the Basket". It is a simple game. You have to throw a ball into a basket from a certain dista

LightOJ1317---Throwing Balls into the Baskets 解题心得

原题: Description You probably have played the game "Throwing Balls into the Basket". It is a simple game. You have to throw a ball into a basket from a certain distance. One day we (the AIUB ACMMER) were playing the game. But it was slightly diff

LightOJ1317---Throwing Balls into the Baskets (概率dp)

You probably have played the game "Throwing Balls into the Basket". It is a simple game. You have to throw a ball into a basket from a certain distance. One day we (the AIUB ACMMER) were playing the game. But it was slightly different from the m

hdu-5810 Balls and Boxes(概率期望)

题目链接: Balls and Boxes Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Problem Description Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. In the experiment, he

LightOJ 1038 - Race to 1 Again(期望+DP)

题目链接:http://lightoj.com/volume_showproblem.php?problem=1038 题意是:给你一个N (1 ≤ N ≤ 105) 每次N都随机选一个因子d,然后让N=N/d, 求N变成1的次数的期望: 当 N = 2 时 2有两个因子:1,2 E[2] = E[1]/2 + E[2]/2 + 1;因此可以求出E[2]; 当N = 8 时 8有4个因子1 2 4 8; E[8] = E[1]/4 + E[2]/4 + E[4]/4 + E[8]/4+ 1;因此

博客园首页新随笔联系管理订阅 随笔- 524 文章- 0 评论- 20 hdu-5810 Balls and Boxes(概率期望)

Balls and Boxes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 798    Accepted Submission(s): 527 Problem Description Mr. Chopsticks is interested in random phenomena, and he conducts an experi