- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSushi.java
More file actions
Latest commit
45 lines (36 loc) · 1.09 KB
/
Copy pathSushi.java
File metadata and controls
45 lines (36 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
importjava.util.*;
importjava.io.*;
publicclassSushi {
publicstaticvoidmain(String[] args) throwsIOException {
BufferedReaderbr = newBufferedReader(newInputStreamReader(System.in));
doublen = Double.parseDouble(br.readLine());
String[] s = br.readLine().split(" ");
int[] arr = newint[4];
for (intq = 0; q < n; q++) {
arr[Integer.parseInt(s[q])]++;
}
intm1 = arr[1] + arr[2] + arr[3];
intm2 = arr[2] + arr[3];
intm3 = arr[3];
intt = (int) n + 1;
double [][][] dp = newdouble[t][t][t];
for (intk = 0; k <= m3; k++) {
for (intj = 0; j <= m2-k; j++) {
for (inti = 0; i <= m1-j-k; i++) {
// System.out.println(i + " " + j + " " + k);
if (i == 0 && j == 0 && k == 0)
continue;
intsum = i + j + k;
dp[i][j][k] = n / sum;
if (i != 0)
dp[i][j][k] += (double) dp[i - 1][j][k] * i / sum;
if (j != 0)
dp[i][j][k] += (double) dp[i + 1][j - 1][k] * j / sum;
if (k != 0)
dp[i][j][k] += (double) dp[i][j + 1][k - 1] * k / sum;
}
}
}
System.out.println(dp[arr[1]][arr[2]][arr[3]]);
}
}