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
Sample Output
思路:先把1全部列在一条线上,枚举有一个01 两个01,当有一个01时,在n个1前面选择一个,那么这个前面和最后可以放0,也就是把0划分成两部分,同时也要保证
前一部分有0,然后枚举01的个数就可以了
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; }
相关文章推荐
- HDU 5194 DZY Loves Balls(数学组合or各种乱搞)
- HDU 5194 DZY Loves Balls (组合数学)
- HDU 5194——DZY Loves Balls
- hdu 5194 DZY Loves Balls【bfs+打表】
- hdu 5194 DZY Loves Balls (dp)
- HDU-5194-DZY Loves Balls(BestCoder Round # 35 )
- HDU 5194 DZY Loves Balls
- hdu 5194 DZY Loves Balls(暴力,数学期望)
- 【CUGBACM15级BC第35场 A】hdu 5194 DZY Loves Balls
- HDU5194 DZY Loves Balls【排列组合】
- HDU 5194 DZY Loves Balls(概率)
- HDU 5194 DZY Loves Balls
- hdu 5194 DZY Loves Balls
- HDU 5194 DZY Loves Balls(期望可加性)
- hdu 5645 DZY Loves Balls
- HDOJ-5194-DZY Loves Balls 解题报告
- HDOJ 5194 DZY Loves Balls
- hdu-5645 DZY Loves Balls(水题)
- hdoj 5194 DZY Loves Balls【规律&&gcd】
- HDU 5645 DZY Loves Balls(概率)