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

【CATIA的二次开发38】对象Selection交互选择部分方法介绍01 在CATIA V5的VBA开发中,Selection对象是用户交互的核心组件,用于管理用户在图形区域或特征树中的选择操作。Selection 对象是 CATIA VBA 中的中央交互枢纽,充当用户界面与程序逻辑之间的桥梁。它代表当前在图形区域或特征树中被选中的元素集合,是自动化操作的基础。 阅读详情

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 main game. In our game we were N people trying to throw balls into M identical Baskets. At each turn we all were selecting a basket and trying to throw a ball into it. After the game we saw exactly S balls were successful. Now you will be given the value of N and M. For each player probability of throwing a ball into any basket successfully is P. Assume that there are infinitely many balls and the probability of choosing a basket by any player is 1/M. If multiple people choose a common basket and throw their ball, you can assume that their balls will not conflict, and the probability remains same for getting inside a basket. You have to find the expected number of balls entered into the baskets after K turns.
Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing three integers N (1 ≤ N ≤ 16), M (1 ≤ M ≤ 100) and K (0 ≤ K ≤ 100) and a real number P (0 ≤ P ≤ 1). P contains at most three places after the decimal point.
Output

For each case, print the case number and the expected number of balls. Errors less than 10-6 will be ignored.
Sample Input

Output for Sample Input

2

1 1 1 0.5

1 1 2 0.5

Case 1: 0.5

Case 2: 1.000000

Problem Setter: Muhammad Rifayat Samee
Special Thanks: Jane Alam Jan

首先我们要知道每一次扔的时候,0个人扔进的概率,1个人扔进的概率….
由于最后不关心M个篮子里球的具体情况,所以M其实没有什么用
只要区分扔不扔进去,至于扔到哪个篮子不管
dp[i][j]表示到第i轮,篮子里有j个球的概率
最后答案就是Σi⋅dp[k][i]

/*************************************************************************
    > File Name: L.cpp
    > Author: ALex
    > Mail: zchao1995@gmail.com 
    > Created Time: 2015年05月17日 星期日 16时05分37秒
 ************************************************************************/

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector>

using namespace std;

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

double dp[110][1700]; //ith turns, p of j balls 
double Pa[20];
int C[20][20];

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

double Pow(double a, int b) {
    double ans = 1;
    for (int i = 1; i <= b; ++i) {
        ans *= a;
    }
    return ans;
}

int main() {
    init();
    int t;
    int icase = 1;
    scanf("%d", &t);
    while (t--) {
        int n, m, k;
        double p;
        scanf("%d%d%d%lf", &n, &m, &k, &p);
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        for (int i = 0; i <= n; ++i) {
            Pa[i] = C[n][i] * Pow(p, i) * Pow((1 - p), n - i);
        }
        for (int i = 1; i <= k; ++i) {
            for (int j = 0; j <= (i - 1) * n; ++j) {
                for (int l = 0; l <= n; ++l) {
                    if (j + l <= i * n) {
                        dp[i][j + l] += dp[i - 1][j] * Pa[l];
                    }
                }
            }
        }
        double E = 0;
        for (int i = 0; i <= k * n; ++i) {
            E += dp[k][i] * i;
        }
        printf("Case %d: %.12f\n", icase++, E);
    }
    return 0;
}
告别臃肿!保姆级教程:用NTLite深度精简Win10,打造你的专属纯净系统(附完整组件移除清单) 本文提供了一份详细的NTLite教程,帮助用户深度精简Windows10系统,移除冗余组件并优化性能。从准备工作到组件移除清单,再到系统配置优化和无人值守安装,逐步指导用户打造专属纯净系统。附完整组件移除清单和实战经验,确保系统稳定高效运行。 阅读详情

相关推荐

CAS5和CAS6自定义异常提示消息

CAS自定义异常提示消息

weixin_42949219的博客 981

LightOJ - 1364 Expected Cards(概率dp)

题目链接:Expected Cards - LightOJ 1364 - Virtual Judge (ppsucxtt.cn) 题意:Taha 把一副扑克牌(54张)随机洗开,倒扣着放成一摞。然后从上往下依次翻开每张牌,每翻开一张黑桃、红桃、梅花或者方块,就把它放到对应花色的堆里去。Taha想知道得到 A 张黑桃、B 张红桃、C 张梅花、D 张方块需要翻开的牌的张数的期望值 E 是多少?特殊地,如果翻开的牌是大王或者小王,Taha 将会把它作为某种花色的牌放入对应堆中,使得放入之后 E 的值尽可能小。

AC__dream的博客 285

通过两个mark点确定某一个点的位置

read_image (Image0, '0.bmp') binary_threshold (Image0, Region, 'max_separability', 'dark', UsedThreshold) connection (Region, ConnectedRegions) fill_up (ConnectedRegions, RegionFillUp) select_shape_std (RegionFillUp, SelectedRegions, 'max_area', 70) red...

CSDN博客 3891

LightOJ 1364 Expected Cards (概率dp)

题意:54张牌,大小王可以变成任意花色,随机打乱,每次抽一张,使得每种花色都达到一定的数量,求抽卡的期望次数。 题解:概率dp dp[x1][x2][x3][x4][k1][k2]dp[x1][x2][x3][x4][k1][k2]dp[x1][x2][x3][x4][k1][k2]:表示手里四种花色的数量分别为xxxiii,大小王牌分别取哪一种花色时还需要抽卡的期望次数。 对于每一种当前状态,获...

gongyuandaye的博客 287

AMD MI355X与NVIDIA B200在GLM5.2大模型推理性能与成本对比分析

在 AI 推理硬件选型中,成本与性能的平衡一直是技术决策的核心难点。AMD 最新发布的 CDNA 4 架构 MI355X 加速卡与 NVIDIA Blackwell 架构的 B200 在 GLM5.2 这类千亿参数大模型上的表现,直接关系到企业部署私有化模型或提供推理服务的经济性。实际测试数据显示,在 32 tok/s/user 的交互性设定下,单张 MI355X 能够达到 1369 tok/s 的吞吐量,虽然略低于 B200 的 1756 tok/s,但每百万 token 成本仅为 0.30 美元,比 B

weixin_28221501的博客 307

HyperLynx仿真(一)LineSim简单介绍

可以选择设置信号线与信号线之间默认的距离和信号线与同平面的平面之间的距离,这些设置根据工程师项目上经常使用的情况而设置,也可以选择不设置,在每次仿真时根据需要再对每一个仿真单独设置。仿真属性的设置对话框包含一般设置、 显示颜色设置、LineSim 设置、BoardSim 设置、 层叠默认设置、焊盘类型设置、仿真示波器默认设置、电路仿真器默认设置、电源完整性设置及高级设置。第一次使用HyperLynx软件时需要设置仿真相关环境,包括仿真软件的基本设置、模型库路径设置、仿真控制器控制、单位等。...

小幽余生不加糖 8963

ARGUMENT 37 Palean baskets 是否是由Palea村所唯一拥有

<br />TOPIC: ARGUMENT37 - Woven baskets characterized by a particular distinctive pattern have previously been found only in the immediate vicinity of the prehistoric village of Palean and therefore were believed to have been unique to the Palean people. R

Coding for Dreams 5835

爆肝整理:微信公众号文章HTML编写完整规范,运营必备手册

微信公众号文章排版总是出错?📱 这份完整的HTML编写规范文档帮你彻底解决!文档包含所有支持的标签、CSS属性、实用代码模板和注意事项 📋,让你快速掌握微信文章的HTML编写技巧,告别第三方编辑器依赖 ✅

XiaoqiangClub的博客 2354

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...

advyne9986的博客 223

C#实现图片裁剪 (附完整源码)

C#实现图片裁剪 (附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 517

突破限制:巧用Azure OpenAI,畅玩Gemini模型

通过 Azure OpenAI 服务这一巧妙的途径,间接调用 Gemini 模型,打破网络限制的壁垒。本文将详细介绍这一方法,无论你是人工智能领域的新手,还是经验丰富的开发者,都能从中获取实用的技巧,轻松开启 Gemini 模型的探索之旅

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 190

LightOJ 1317 Throwing Balls into the Baskets

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27025 题意:有n个人,m个篮筐,每个人一次投球进的概率为p,每一轮每个人都会投一次球,等概率选择每个篮筐而且之间互不影响。问k轮后进球数量的期望。 思路:既然投哪个篮筐没有影响,我们只需要关心进还是不进,可以直接忽略篮筐,投一次进的概率为p,一

DS-K的博客 503

[网络安全提高篇] 一二九.Powershell恶意代码检测 (5)混淆和反混淆 [上]

前文介绍了如何利用MS Defender实现恶意样本家族批量标注。这篇文章将继续讲解Powershell恶意代码检测,主要包括PowerShell混淆与反混淆内容,首先结合Invoke-Obfuscation工具详细介绍PowerShell代码混淆方法,再结合PowerDecode工具阐述解混淆方法。该研究将为后续的恶意软件家族分类或溯源提供帮助。未完待续,基础性文章,希望您喜欢,且看且珍惜。

杨秀璋的专栏 1604

LightOJ 1317 Throwing Balls into the Baskets(概率dp)

题解: 每个篮子的选择概率都是 1/m,所以可以每一次投球进球概率为 p*1/m+...+p*1/m = p,即每个球的得分概率都是一样的,可以通过公式获得。 #include &lt;algorithm&gt; #include &lt;iostream&gt; #include &lt;cstdlib&gt; #include &lt;cstring&gt; #include ...

yanhu6955的博客 224

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

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 #include using names

嗯。 1166

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

LightOJ 1317 - Throwing Balls into the Baskets

1317 - Throwing Balls into the Baskets     PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You probably have played the game "Throwi

abclydabclyd的博客 486

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

lightOJ 1317 Throwing Balls into the Baskets

DescriptionYou 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 pla

wb129945130的博客 498

LightOJ-1364 Expected Cards(期望dp)

O - Expected Cards  LightOJ - 1364  题解:高维期望dp,dp[i][j][k][s][q][p]表示每种牌分别有i,j,k,s张,Joker的状态分别为q,p时的期望值,用记忆化搜索一下 #include using namespace std; const double eps = 1e-8; double dp[15][15][15][

十分残念的博客 665

lightoj 1317 Throwing Balls into the Baskets

lightoj 1317

ACdream 579

LightOJ 1364 Expected Cards(概率+DP)

题目链接:http://lightoj.com/volume_showproblem.php?problem=1364 题意:一副牌。依次在桌面上放牌。求放了四种花色的牌为C,D,H,S张时放的牌数的期望。大小王出现时必须将其指定为某种花色。指定时要使最后的期望最小。 思路:DP,记录大小王是不是已经被指定过了。 int c,num=0; int C,D,H,S; d...

weixin_33901926的博客 227

LightOJ-1342 Aladdin and the Magical Sticks(期望dp)

N - Aladdin and the Magical Sticks  LightOJ - 1342  题解:期望dp。设不可分辨的木棍个数为n1,平均权值为tot1,可分辨的木棍个数为n2,平均权值为tot2 对于dp[i][j],表示已拿过i个不可分辨的木棍和j个可分辨的木棍,那么还剩sum=n1+n2-j个木棍 dp[i][j]=(n1-i)/sum*(dp[i+1][j

十分残念的博客 878

Lightoj 1342(求期望)

链接:点击打开链接 题意:有N根木棍,每根木棍都有一个权值 其中有若干根可识别,若干根不可识别的,抽到了可识别的棍子,就不放回,抽到了不可识别的,就要放回 ,问所有棍子都至少被抽过一次后权值和的期望 代码:#include #include #include #include #include #include using namespace std; double f[5005]

stay_accept的专栏 776

LightOJ-1317 Throwing Balls into the Baskets

水题,输出n*p*k即可 刚开始觉得m没用,以为看错了题,提交后发现m真的没用 因为每个篮筐概率都一样,而且不冲突,就当作n个人向一个篮筐投球k次,进球概率为p 所以期望是n*p*k #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;algorithm&gt; #incl...

wl16wzl的博客 190

LightOJ - 1364 Expected Cards (概率期望)

题目:给你一副扑克牌,54张,让你求出取出黑梅红方最少分别为a,b,c,d张 的取的次数的期望。其中大小王可以当做四种牌的任意一种。 题解:dp[a][b][c][d][p][q]表示每种牌分别有a,b,c,d张,Joker的状态分别作为p和q出现时的期望值,然后记忆化搜索。(dp状态想到了,但是没能实现,参考一位大佬的方法%%%%%) #include&lt;bits/stdc++.h&g...

XFire的博客 639

LightOJ 1364 Expected Cards 期望DP+记忆化搜索

Expected Cards LightOJ - 1364 有 545454 张牌,其中♣ ♦ ♥ ♠ 各有 131313 张,还有两张大小王,现在从洗好的牌里依次抽,问抽到至少 CCC 张梅花,DDD 张方片,HHH 张红桃,SSS 张黑桃所需要抽的期望张数是多少?假如抽到大小王的话,可以令他们为任意的花色,但是必须立刻指定他们的花色,不能随后更改。 用 dp[c][d][h][s][i][j]...

wineandchord 223

[LightOJ 1364] Expected Cards (高维期望DP)

LightOJ - 1364 一副扑克牌,不断地从中抽牌 要求四种花色都至少要有给定的张数 其中如果抽到了王牌,可以将其变为任意花色 求满足条件时,抽出的期望张数 刚开始想错了,两张王牌并非在一开始就给定了 而是在游戏中可以视当前情况选择着变的 这两种方式是不一样的由于牌数其实并不会很多, 复杂度乘一乘发现才 10710^7级别的,所以直接暴力DP将两张王牌当前变成了什么

MisDeer's blog 738
上一篇: LightOJ1027---A Dangerous Maze (期望)
下一篇: LightOJ1364---Expected Cards(概率dp+三进制状压)
tokers
博客等级 码龄12年 71粉丝 700原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值