Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- created: 2022-08-29-01.49.51
- ***/
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
- #define ll long long
- #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
- #define get_lost_idiot return 0
- #define nl '\n'
- double dp[2][501][501];
- bool v[2][501][501];
- double solve(ll r,ll b,ll c)
- {
- if(r==0 && b==1) return 1.00;
- if(v[c][r][b]) return dp[c][r][b];
- double ans=0.00;
- v[c][r][b]=1;
- if(!c)
- {
- if(r)
- {
- ans+=((1.00*r)/((r+b)*1.00))*solve(r-1,b,c^1);
- }
- if(b)
- {
- ans+=((1.00*b)/((r+b)*1.00))*solve(r,b-1,c^1);
- }
- }
- else
- {
- if(b)
- {
- ans+= /*((1.00*b)/((r+b)*1.00))* */ solve(r,b-1,c^1);
- // this can't contribute to my winning probability
- }
- }
- return dp[c][r][b]=ans;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- test
- {
- ll r,b;
- cin>>r>>b;
- //memset(v,0,sizeof v);
- cout<<"Case "<<cs<<": "<<fixed<<setprecision(12)<<solve(r,b,0)<<nl;
- }
- get_lost_idiot;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement