Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ll long long
- #include <iostream>
- using namespace std;
- const int OO = 1e9;
- const double EPS = 1e-9;
- int n,s;
- double mem[1001][1001];
- double solve(int cn, int cs) {
- if(cn == 0 && cs == 0) {
- return 0;
- }
- if(mem[cn][cs] != -1)
- return mem[cn][cs];
- double pn = (1.0*cn)/n;
- double ps = (1.0*cs)/s;
- double &ret = mem[cn][cs];
- ret = 0;
- if(cn > 0 && cs > 0) {
- ret += pn*ps*(1 + solve(cn-1,cs-1));
- }
- if(cn > 0) {
- ret += pn*(1-ps)*(1+solve(cn-1,cs));
- }
- if(cs > 0) {
- ret += (1-pn)*ps*(1+solve(cn,cs-1));
- }
- ret += (1-pn)*(1-ps);
- ret /= (1-(1-pn)*(1-ps));
- return ret;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- cin >> n >> s;
- for(int i = 0; i <= n; i++) {
- for(int j = 0; j <= s; j++) {
- mem[i][j] = -1;
- }
- }
- cout.precision(4);
- cout << fixed << solve(n,s) << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement