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
| #include <cstdio> using namespace std; template <class Type> void read(Type &x) { char c; bool flag = false; while ((c = getchar()) < '0' || c > '9') c == '-' && (flag = true); x = c - '0'; while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0'; flag && (x = ~x + 1); } template <class Type> void write(Type x) { x < 0 && (putchar('-'), x = ~x + 1); x > 9 && (write(x / 10), 0); putchar(x % 10 + '0'); } const int N = 1e3 + 10; int n, m; double f[N][N][3]; double dfs (int x, int y, int op) { if (f[x][y][op] > 1e-10) return f[x][y][op]; if (!x || y < 0) return 0; if (op == 0) return f[x][y][op] = (double)x / (x + y) + (double)y / (x + y) * dfs(x, y - 1, 1); else if (op == 1) return f[x][y][op] = (double)y / (x + y) * dfs(x, y - 1, 2); return f[x][y][op] = (double)x / (x + y) * dfs(x - 1, y, 0) + (double)y / (x + y) * dfs(x, y - 1, 0); } int main () { read(n), read(m); printf("%.12lf", dfs(n, m, 0)); return 0; }
|