-
Notifications
You must be signed in to change notification settings - Fork 34
/
1050-Marbles.cpp
43 lines (43 loc) · 1 KB
/
1050-Marbles.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// amiD
#include <bits/stdc++.h>
#define ld long double
#define ll long long int
#define mod 1000000007
#define ll_inf 1000000000000000
#define int_inf 1000000000
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define eps 1e-9
#define PI acos(-1.0)
#define ii pair<int,int>
#define se second
#define fi first
using namespace std;
bool vis[505][505];
double dp[502][505];
double cal(int red, int blue){
if(red==0){
if(blue%2==0)return dp[red][blue]=0.0;
return dp[red][blue]= 1.0;
}
if(blue==0)return dp[red][blue]=0.0;
if(blue<=0)return 0.0;
double &ret=dp[red][blue];
if(vis[red][blue])return dp[red][blue];
vis[red][blue]=1;
ret=1.0;
ret=((1.0*red)/(red+blue)*cal(red-1, blue-1));
if(blue>=2)ret+=((1.0*blue)/(red+blue)*cal(red, blue-2));
return ret;
}
int main(){
cout.precision(12);
int t, ca=1;
cin>>t;
while(t--){
int red,blue;
scanf("%d%d",&red, &blue);
printf("Case %d: %.8f\n", ca++, cal(red, blue));
}
}