1 solutions

  • 0
    @ 2024-10-16 23:53:53
    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 15, inf = 1e8;
    
    double f[N][N][N][N][5][5];
    int A, B, C, D;
    bool v[N][N][N][N][5][5];
    
    void add(int x, int y, int &a, int &b, int &c, int &d) {
        a += (x == 0) + (y == 0);
        b += (x == 1) + (y == 1);
        c += (x == 2) + (y == 2);
        d += (x == 3) + (y == 3);
    }
    
    double dfs(int a, int b, int c, int d, int x, int y) {
        if(v[a][b][c][d][x][y]) return f[a][b][c][d][x][y];
        v[a][b][c][d][x][y] = 1;
        double &ans = f[a][b][c][d][x][y] = 0;
        int na = a, nb = b, nc = c, nd = d;
        add(x, y, na, nb, nc, nd);
        if (na >= A && nb >= B && nc >= C && nd >= D) return 0;
    	int w = 54 - na - nb - nc - nd;
    	if (w <= 0) return ans = inf;
    	if (a < 13) ans += dfs(a + 1, b, c, d, x, y) * (13 - a) / w;
    	if (b < 13) ans += dfs(a, b + 1, c, d, x, y) * (13 - b) / w;
    	if (c < 13) ans += dfs(a, b, c + 1, d, x, y) * (13 - c) / w;
    	if (d < 13) ans += dfs(a, b, c, d + 1, x, y) * (13 - d) / w;
        double x_val = inf, y_val = inf;
        for(int i = 0; i < 4; i ++ ) {
            if(x == 4) x_val = min(x_val, dfs(a, b, c, d, i, y) / w);
            if(y == 4) y_val = min(y_val, dfs(a, b, c, d, x, i) / w);
        }
        if(x == 4) ans += x_val;
        if(y == 4) ans += y_val;
        return ++ ans;
    }
    
    int main() {
        cin >> A >> B >> C >> D;
        double ans = dfs(0, 0, 0, 0, 4, 4);
        if(ans >= inf) puts("-1.000");
        else printf("%.3lf", ans);
        return 0;
    }
    

    让我的后辈们帮我补充题解

    • 1

    Information

    ID
    505
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    1
    Accepted
    1
    Uploaded By