# 京东2017实习生真题 - 通过考试

2017-04-10

4
50 50 50 50

0.31250

C/C++语言：1000MS其它语言：3000MS

C/C++语言：65536KB其它语言：589824KB

```假设小明考了3道题,每道题成功的概率如下:

r为0,n为3,表示3道题,全错的概率;;小明如果考了三道题,则全错的概率为0.12
r\n     0       1       2       3           记录
0       1       0.6     0.24    0.12        全错
1       0       0.4     0.52    0.38        对一道题
2       0       0       0.24    0.38        对两道题
3       0       0       0       0.12        对三道题

1.首先,全错的概率:错1*错2*....错n

2.你再仔细看看上面那张表,到底有什么规律,它的奥秘将会在下面揭示

double[][] dp = new double[n + 1][n + 1];
dp[0][0] = 1;
for (int i = 1; i < n + 1; i++) {
dp[i][0] = dp[i - 1][0] * (1 - p[i - 1]);
for (int j = 1; j < n + 1; j++){
dp[i][j] = dp[i - 1][j - 1]*p[i - 1]+dp[i-1][j]*(1- p[i - 1]);
}
}
-------------------------看懂的到此为止,还需要往下面看的,编程或许不适合你
-----------------------------------------------------------------

r\n     0       1
0       1       0.6
1       0       0.4

r\n     0       1       2
0       1       0.6     0.24
1       0       0.4     0.52
2       0       0       0.24

r\n     0       1       2       3
0       1       0.6     0.24    0.12
1       0       0.4     0.52    0.38
2       0       0       0.24    0.38
3       0       0       0       0.12

```import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);
int n = in.nextInt();
double[] p = new double[n];
for (int i = 0; i < n; i++) p[i] = (double)in.nextInt() / 100;
double[][] dp = new double[n + 1][n + 1];
dp[0][0] = 1;
for (int i = 1; i < n + 1; i++) {
dp[i][0] = dp[i - 1][0] * (1 - p[i - 1]);
for (int j = 1; j < n + 1; j++){
dp[i][j] = dp[i - 1][j - 1] * p[i - 1] + dp[i - 1][j] * (1 - p[i - 1]);
}
}
double result = 0;
for (int i = (3 * n + 4) / 5; i <= n; i++) {
result += dp[n][i];
}
System.out.println(String.format("%.5f", result));
in.close();
}
}```