是计算抽中什么当期五星的期望。
现在的程序结果是99.6087
。结果不对,有时间再调。
#include <iostream>
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;int n = 90;
double p;
// double min_p = 1e-7;
double min_p = 0.0000000000000001;
vector<vector<double>> dp;// x 0 保底、1 不保底
// y 0 必、1-89 不必
// acc 累计概率
// 返回抽到当期期望数
double dfs(int x, int y, double acc){if(dp[x][y] != -1) return dp[x][y] + 1;if(acc <= min_p) {// TODOcout << x << " " << y << " " << acc << " " << dp[x][y] << "==================" << endl;return 1e18;}double g = 1;if(x == 1 && y == 0){dp[x][y] = 0.5 + 0.5 * dfs(0, 1, acc * 0.5);} else if(x == 0){dp[x][y] = p + (g-p) * dfs(0, (y+1) % n, acc * (g-p));} else{dp[x][y] = p/2 + (p/2) * dfs(0, (y+1) % n, acc * (p/2)) + (g-p) * dfs(1, (y+1) % n, acc * (g-p));}cout << x << " " << y << " " << acc << " " << dp[x][y] << endl;// xxx: 注意!!!要加1return dp[x][y] + 1;
}int main() {// int a, b;// while (cin >> a >> b) { // 注意 while 处理多个 case// cout << a + b << endl;// }freopen("D:\\auxiliaryPlane\\project\\scuCode\\input.txt","r",stdin);freopen("D:\\auxiliaryPlane\\project\\scuCode\\output.txt","w",stdout);// cin >> p;p = 0.006;// 输出 104.5497057// 要求误差在1e-6内dp = vector<vector<double>>(2, vector<double>(n, -1));// 是否保底,连续没五次数 下次期望// 估计一个当前概率阈值dp[0][0] = 0;cout << dfs(1, 1, 1);// cout << 1;// cout << min_p;// printf("%.3f", min_p);
}
// 64 位输出请用 printf("%lld")