码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5194 DZY Loves Balls

时间:2015-08-13 21:55:56      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

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

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int m,n;
 6 void build(int x,int y,int t1,int t2,int &ans1,int &ans2)
 7 {
 8     int a,b;
 9     if (t2==m) {ans1=1;ans2=1;return ;}
10     if (t1==n)
11     {
12         if (x==0) ans2=1;
13         else ans2=0;
14         ans1=1;
15         return ;
16     }
17     build(y,0,t1,t2+1,ans1,ans2);
18     a=ans1;
19     b=ans2;
20     build(y,1,t1+1,t2,ans1,ans2);
21     a+=ans1;
22     b+=ans2;
23     if (x==0&&y==1) b+=a;
24     ans1=a;
25     ans2=b;
26 }
27 int main()
28 {
29     int a,b,c,ans1,ans2;
30     while (~scanf("%d%d",&n,&m))
31     {
32         build(-1,0,0,1,ans1,ans2);
33         a=ans1;b=ans2;
34         build(-1,1,1,0,ans1,ans2);
35         a+=ans1;b+=ans2;
36         n=b;
37         m=a;
38         a=max(n,m);
39         b=min(n,m);
40         c=1;
41         while (c)
42         {
43             c=a%b;
44             a=b;
45             b=c;
46         }
47         printf("%d/%d\n",n/a,m/a);
48     }
49     return 0;
50 }

 

hdu 5194 DZY Loves Balls

标签:

原文地址:http://www.cnblogs.com/pblr/p/4728291.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!