爱奇艺笔试第二题
public class S2 {
public static void main(String[] args) {
int n = 3;
int m = 4;
System.out.format("%.5f", cal(n, m));
}
private static double cal(int n, int m) {
if (n >= 1 && m == 0) {
return 1;
}
if (n <= 0 || m <= 0) {
return 0;
}
double curr = n / (m + n + 0.0);
double fail = allFail(n, m);
double next1 = cal(n - 1, m - 2);
double next0 = cal(n, m - 3);
curr = curr + fail * (((m - 2) / (n + m - 2.0)) * next0 + (1 - (m - 2) / (n + m - 2.0)) * next1);
return curr;
}
/**
* A B 全部不胜利,可以进入下一轮
*/
private static double allFail(int n, int m) {
if (m < 2) {
return 0;
}
return m / (n + m + 0.0) * (m - 1) / (n + m - 1.0);
}
} #爱奇艺##题解#
查看8道真题和解析
