hdu5194 DZY Loves Balls 【概率论 or 搜索】
//yy:那天考完概率论,上网无聊搜个期望可加性就搜到这题,看到以后特别有亲和感,挺有意思的。
hdu5194 DZY Loves Balls 【概率论 or 搜索】
题意:
一个盒子里有n个黑球和m个白球【n,m≤12】。每次随机从盒子里取走一个球,取了n+m次后,刚好取完。现在用一种方法生成了一个随机的01串S[1…(n+m)],如果第i次取出的球是黑色的,那么S[i]=1,如果是白色的,那么S[i]=0。求'01'在S串中出现的期望次数。
题解:
求出在第i个位置上出现0,第i+1个位置上出现1的概率,这种情况设为Xi = 1,这就是二项分布啦,
根据期望的可加性,有E∑Xi = N * P。(期望的可加性不要求事件相互独立喔,方差要求
,所以可以这样做吖)
Xi = 1的概率 P = m / (n + m) * n / (n + m - 1)
由题意可知这里的 N = (n + m - 1)
化简一下答案就出来了: n * m / (n + m)
#include <cstdio>
#include <algorithm>
using namespace std;
int gcd(int a, int b) {return b ? gcd(b, a%b) : a;}
int main() {
int m, n, x;
while(~scanf("%d%d", &m, &n)) {
x = gcd(m*n, m+n);
printf("%d/%d\n", m*n/x, (m+n)/x);
}
return ;
}
还有个搜索方法,房教写的,膜拜ORZ
get一个快遗忘的知识点,用常引用减小开栈的开销。。。如果既要利用引用提高程序的效率,又要保护传递给函数的数据不在函数中被改变,就应使用常引用。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long dp[][];
long long C[][];
long long ans = ;
ll dfs(const int& x,const int& y,const int& st)
{
if(st==&&dp[x][y]!=-) return dp[x][y];
long long ans = ;
if(st==){
if(x>){
ans += C[x+y-][y] + dfs(x-,y,);
}
if(y>)
{
ans += dfs(x,y-,);
}
}
if(st==){
if(x>){
ans += dfs(x-,y,);
}
if(y>)
{
ans += dfs(x,y-,);
}
}
if(st==)dp[x][y] = ans;
return ans;
}
void get_C(int maxn)
{
C[][] = ;
for(int i=;i<=maxn;i++)
{
C[i][] = ;
for(int j=;j<=i;j++)
C[i][j] = C[i-][j]+C[i-][j-];
//C[i][j] = (C[i-1][j]+C[i-1][j-1])%MOD;
}
}
int main(){
memset(dp,-,sizeof(dp));
dp[][] = ;
get_C();
int n,m;
while(scanf("%d%d",&n,&m)==)
{
ll b=C[n+m][n];
ll sum=dfs(n,m,);
ll a=__gcd(sum,b);
printf("%lld/%lld\n",sum/a,b/a);
}
return ;
}
hdu5194 DZY Loves Balls 【概率论 or 搜索】的更多相关文章
- HDU 5194 DZY Loves Balls
DZY Loves Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- hdu 5645 DZY Loves Balls
DZY Loves Balls Accepts: 659 Submissions: 1393 Time Limit: 4000/2000 MS (Java/Others) Memory Lim ...
- HDU 5645 DZY Loves Balls 水题
DZY Loves Balls 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5645 Description DZY loves playing b ...
- hdoj 5194 DZY Loves Balls【规律&&gcd】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5194 题意:给你n个黑球,m个白球,每次从中随机抽取一个,如果抽到黑球记为1如果抽出来白球记为0,让你 ...
- BC#76.2DZY Loves Balls
DZY Loves Balls Accepts: 659 Submissions: 1393 Time Limit: 4000/2000 MS (Java/Others) Memory Lim ...
- 周赛-DZY Loves Chessboard 分类: 比赛 搜索 2015-08-08 15:48 4人阅读 评论(0) 收藏
DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input standard ...
- BZOJ 3512: DZY Loves Math IV [杜教筛]
3512: DZY Loves Math IV 题意:求\(\sum_{i=1}^n \sum_{j=1}^m \varphi(ij)\),\(n \le 10^5, m \le 10^9\) n较小 ...
- hdoj5645DZY Loves Balls
Problem Description DZY loves playing balls. He has n balls in a big box. On each ball there is an i ...
- CF444C. DZY Loves Colors[线段树 区间]
C. DZY Loves Colors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- currentStyle、getComputedStyle 获取样式
style.height 获取的是行间的样式 currentStyle.height.getComputedStyle(elem,null).height 获取的是 div 的 content 的宽高 ...
- SSRS Report Knowledge Base
1. 获取Textbox的值,根据Textbox值更改单元格颜色 Textbox值:=ReportItems!Textbox1.Value 当前单元格的值:=Me.Value =IIF(ReportI ...
- Error -4075: File not found. An error occurred merging module <MODULENAME> for feature <FEATURENAME>.
利用Install Shield2010制作安装包的时候一直报这样的错误,原以为是我自己安装包制作流程的问题,又重新做了2个,但是还是出现问题. 解决办法: 查找资料发现是Install Shield ...
- 三:Maven创建问题
1.httpServlet was not found 设置server为tomcat,jre设置为安装的jdk的jre java build path 添加server runtime为tomcat ...
- JAVA线程池的原理分析
线程池的作用 1.降低资源的消耗 2.提高效率 3.方便管理 相关概念 corePoolSize核心线程数:核心池的大小,当有任务到达之后,就会创建一个线程去执行任务,当任务数量到达核心线程数后,就会 ...
- MySQL prompt命令
修改提示符,设置后挺方便的 例如: 几个好用的参数 \d 当前数据库 \u 当前用户 \h 当前主机 更多参数可以参考mysol官方文档 参考文档:https://dev.mysql.com/doc/ ...
- ApplicationContextAware接口
在某些特殊的情况下,Bean需要实现某个功能,但该功能必须借助于Spring容器才能实现,此时就必须让该Bean先获取Spring容器,然后借助于Spring容器实现该功能.为了让Bean获取它所在的 ...
- Ajax实现页面跳转与结果返回
ajax实现页面局部跳转与结果返回 1.带有结果返回的提交过程 这里用一个提交按钮来演示,HTML代码为: <input type="button" class=" ...
- java计数
计数 package com.demo; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent ...
- maven(5)--依赖特性
依赖的子标签中有scope,常用值有compile.provide.test.runtime compile:编译范围有效,即编译和打包时都会将这个依赖存储 provide:编译测试有效,但是打包是将 ...