https://dashoj.com/homework/675fcd7cc4c1261f5836f5a8
打完csp后大脑很迟钝很迟钝,这道题都改了20min。
可能是被之前几道概率题创晕了,看到这个数据范围就该想到记忆化搜索的,gpt都会做www
不过每次看到概率大脑都有点宕机,故记一下。
vector<vector<double>> st(1010,vector<double>(1010,-1));
double solve(int w,int b){
double &v = st[w][b];
if(v >= 0) return v;
double dw = (double )w;
double db = (double )b;
double win = dw/(dw+db);
if(b==1){
return v = win;
}else{
double nxt = db/(dw+db)*(db-1)/(dw+db-1);
v = win + nxt *( dw/(dw+db-2)*solve(w-1,b-2) + (db-2)/(dw+db-2)*solve(w,b-3));
}
return v;
}
void solve(){
int W,B;
cin>>W>>B;
for(int i=1;i<=W;i++) st[i][0] = 1.0;
for(int i=0;i<=B;i++) st[0][i] = 0.0;
cout<<fixed<<setprecision(10)<<solve(W,B)<<endl;
}