-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1050.cpp
68 lines (48 loc) · 1.16 KB
/
1050.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI (acos(-1))
#define ct cout<<
#define cn cin>>
#define spc <<" "<<
#define nl puts("")
#define _fl(x) puts("FLAG " #x);
#define _(x) cout<< #x <<" is "<< x <<endl;
#define fs first
#define sc second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define _109 (1000000000)
#define _0(arr) memset(arr,0,sizeof ( arr ) )
#define _1(arr) memset(arr,-1,sizeof ( arr ) )
#define _ninp(n,arr) for(int i=0; i<n;i++)cin>>arr[i];
#define _nout(n,arr) for(int i=0; i<n;i++)cout<<arr[i]<<" \n"[i==n-1];
double _eps=1e-6;
double dp[510][510];
bool mark[510][510];
double f(int red,int blue){
if(red==0)return 1;
if(blue==0){
return 0;
}
if(mark[red][blue])return dp[red][blue];
double tot=red+blue;
double A=(red)*f(red-1,blue-1);
double B=0;
if(blue>=2)B=(blue)*f(red,blue-2);
double res=(A+B)/tot;
mark[red][blue]=true;
return dp[red][blue]=res;
}
int main() {
f(500,500);
int T;
cn T;
for(int caseno=1; caseno<=T ;caseno++){
int n,m;
cn n>>m;
printf("Case %d: %.10f\n",caseno,f(n,m));
}
return 0;
}