HDU 5194 DZY Loves Balls(排列组合瞎搞 )

本文探讨了在特定条件下计算序列中'01'出现次数的期望值问题,通过组合数学的方法解决,提供了实例解析。
Problem Description
There are n black balls and m white balls in the big box.

Now, DZY starts to randomly pick out the balls one by one. It forms a sequence S. If at the i-th operation, DZY takes out the black ball, Si=1, otherwise Si=0.

DZY wants to know the expected times that '01' occurs in S.
 


Input
The input consists several test cases. (TestCase150)

The first line contains two integers, n, m(1n,m12)
 


Output
For each case, output the corresponding result, the format is p/q(p and q are coprime)
 


Sample Input
1 1 2 3
 


Sample Output
1/2 6/5
Hint
Case 1: S='01' or S='10', so the expected times = 1/2 = 1/2 Case 2: S='00011' or S='00101' or S='00110' or S='01001' or S='01010' or S='01100' or S='10001' or S='10010' or S='10100' or S='11000', so the expected times = (1+2+1+2+2+1+1+1+1+0)/10 = 12/10 = 6/5

 
思路:先把1全部列在一条线上,枚举有一个01  两个01,当有一个01时,在n个1前面选择一个,那么这个前面和最后可以放0,也就是把0划分成两部分,同时也要保证
     前一部分有0,然后枚举01的个数就可以了



#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>


#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8

#define fre(i,a,b)  for(i = a; i <b; i++)
#define free(i,b,a) for(i = b; i >= a;i--)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define ssf(n)      scanf("%s", n)
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define bug         pf("Hi\n")

using namespace std;
typedef __int64 ll;

#define INF 0x3f3f3f3f
#define N 10005

ll C(ll a,ll b)
{
    ll x=1,y=1;
    ll i;

    b=min(b,a-b);
    if(b==0) return 1;

    fre(i,1,b+1)
     {
     	 x=x*a;
     	 y=y*i;
     	 a--;
     }
   return x/y;
}

ll fdd(ll x,ll y)
{
	if(y==0) return x;
	return fdd(y,x%y);
}

int main()
{
	ll i,j;
	ll n,m;

	while(~scanf("%I64d%I64d",&n,&m))
	{
		j=min(n,m);

	   ll ans=0;

		fre(i,1,j+1)
		  ans=ans+i*C(n,i)*C(m,i);

		ll y=C(n+m,n);

		ll x=fdd(ans,y);

		pf("%I64d/%I64d\n",ans/x,y/x);

	}
	return 0;
}










评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值