您的位置:首页 > 其它

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

2015-03-28 22:36 423 查看
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. (TestCase≤150)

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


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

HintCase 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: