#include #include #include #include using namespace std; typedef long double ld; int main() { int c; long long t, r; ld p; cin >> c >> t >> r >> p; // time_to_type, dp = [0] * (c + 1), [[0] * (c + 1) for _ in range(c + 1)] ld time_to_type[c + 1], dp[c + 1][c + 1]; time_to_type[0] = 0; for (int i = 0; i <= c; i++) { for (int j = 0; j <= c; j++) dp[i][j] = 0; } // time_to_type[x] is the expected time to type x characters without saving at any time. // Derived from: time_to_type[x] = dp[0][x] + 1-p + p * (1 + r + time_to_type[x]) for (int i = 1; i <= c; i++) { time_to_type[i] = (time_to_type[i - 1] + 1 + p * r) / (1 - p); } // dp[x][y] is the time required to type all characters between indices x (inclusive) and y (exclusive). for (int l = 1; l <= c; l++) { for (int s = 0; s <= c - l; s++) { int e = s + l; dp[s][e] = min(time_to_type[e - s], 1e18l); for (int k = s + 1; k < e; k++) dp[s][e] = min(dp[s][e], dp[s][k] + t + dp[k][e]); } } cout << setprecision(20) << dp[0][c] + (ld) t << endl; }