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 ...
随机推荐
- MySql下载
一般企业办的mysql下载不到 1.准备 注册一个orcle账号 2.跳转到http://www.mysql.com/ ,然后点击Downloads导航栏 滚动到最下面并点击[Community(GP ...
- Frequency-tuned Salient Region Detection MATLAB代码出错修改方法
论文:Frequency-tuned Salient Region Detection.CVPR.2009 MATLAB代码运行出错如下: Error using makecform>parse ...
- 如何限制html标签input的长度
如何限制html标签input的长度 示例: <form action="/example/html/form_action.asp" method="get&qu ...
- .netCore2.0 程序集DI依赖注入
传统的依赖注入确实简单,但是随着项目的扩展随之而来的问题又来了,因为传统的注入是单个类和接口注入的,加入项目的接口和类增加到了上百个的话,就需要在Startup.cs中复制注入上百次,虽然能解决问题, ...
- svn update 报错,必须先cleanup,然后cleanup失败解决方法
一 问题描述: 1.svn update失败,提示已被locked,请执行cleanup 2.执行svn cleanup,提示cleanup failed to process the followi ...
- storm之topology的启动
一个topology的启动包括了三个步骤 1)创建TopologyBuilder,设置输入源,输出源 2)获取config 3)提交topology(这里不考虑LocalCluster本地模式) 以s ...
- JavaScript事件流--事件冒泡、目标与事件捕获
1.事件冒泡 微软提出了名为事件冒泡的事件流.事件冒泡可以形象地比喻为把一颗石头投入水中,泡泡会一直从水底冒出水面.也就是说,事件会从最内层的元素开始发生,一直向上传播,直到document对象. 因 ...
- MySQL数据库、表的字符编码
用MySQL命令行新建数据库和表时默认的字符编码是latin1,但是在实际开发过程中一般都是使用utf8格式的编码.操作如下: 1.修改数据库字符编码 mysql> alter database ...
- EditText的setInputType方法里面应该填什么?
转自CSDN:http://blog.csdn.net/u014158743/article/details/52488010 | 以密码类型(password)为例 android:inputTyp ...
- as3.2版本中中jar生成方法
lintOptions { abortOnError false } task makeJar(type: Copy) { //删除存在的 delete 'build/libs/myjar.jar' ...