【題解】AtCoder ABC 184D – increment of coins

【題目敘述】https://atcoder.jp/contests/abc184/tasks/abc184_d

#include <bits/stdc++.h>
using namespace std;

int a, b, c, anscnt;
double dp[105][105][105], ans;

double dfs(int i, int j, int k){
    if (i == 100 || j == 100 || k == 100) return 0;
    if (dp[i][j][k]) return dp[i][j][k];
    dp[i][j][k] += (double)i/(i+j+k)*(dfs(i+1, j, k)+1);
    dp[i][j][k] += (double)j/(i+j+k)*(dfs(i, j+1, k)+1);
    dp[i][j][k] += (double)k/(i+j+k)*(dfs(i, j, k+1)+1);
    return dp[i][j][k];
}

int main(){
    cin >> a >> b >> c;
    cout << fixed << setprecision(9) << dfs(a, b, c) << "\n";
}

分享本文 Share with friends