HDU 5194 DZY Loves Balls(排列组合瞎搞 )
来源:互联网 发布:logo图形设计软件 编辑:程序博客网 时间:2024/05/22 14:34
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 sequenceS . 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 inS .
Now, DZY starts to randomly pick out the balls one by one. It forms a sequence
DZY wants to know the expected times that '01' occurs in
Input
The input consists several test cases. (TestCase≤150 )
The first line contains two integers,n ,m(1≤n,m≤12)
The first line contains two integers,
Output
For each case, output the corresponding result, the format isp/q (p and q are coprime)
Sample Input
1 12 3
Sample Output
1/26/5HintCase 1: S='01' or S='10', so the expected times = 1/2 = 1/2Case 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 10005ll 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;}
1 0
- HDU 5194 DZY Loves Balls(排列组合瞎搞 )
- HDU 5194 DZY Loves Balls(概率)
- HDU 5194 DZY Loves Balls
- HDU 5194 DZY Loves Balls
- HDU 5194 DZY Loves Balls
- HDU5194 DZY Loves Balls【排列组合】
- hdu DZY Loves Balls
- HDU 5194 DZY Loves Balls (组合数学)
- hdu 5194 DZY Loves Balls(暴力,数学期望)
- hdu 5194 DZY Loves Balls (dp)
- HDU 5194——DZY Loves Balls
- hdu 5194 DZY Loves Balls(组合数学)
- HDU 5194 DZY Loves Balls(期望可加性)
- hdu 5645 DZY Loves Balls
- HDU 5645 DZY Loves Balls
- hdu 5645 DZY Loves Balls
- HDU 5645 DZY Loves Balls
- hdoj 5194 DZY Loves Balls
- CSU 1553 Good subsequence(暴力求解)
- 客户端重定向与服务器端转发
- 杭电OJ第十五届ACM第一题 Hearthstone
- Linux下svn管理命令
- DDD领域驱动设计
- HDU 5194 DZY Loves Balls(排列组合瞎搞 )
- C#非托管资源
- (五)Support Vector Machines[支持向量机]
- IOS开发之多线程与GCD
- 【SICP练习】127 练习3.58
- linux系统在虚拟机上不能使用桥接模式
- 题目:最简单的逆向
- vs2013中静态库lib文件的生成与使用
- android 图形特效处理 Matrix控制变换