-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJ. Problem.cpp
More file actions
47 lines (29 loc) · 834 Bytes
/
J. Problem.cpp
File metadata and controls
47 lines (29 loc) · 834 Bytes
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
46
47
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 302;
double dp[MAXN][MAXN][MAXN];
int N,vis[MAXN][MAXN][MAXN];
double solve(int x,int y,int z){
if(vis[x][y][z]) return dp[x][y][z];
//printf("Solving %d %d %d\n",x,y,z);
vis[x][y][z] = 1;
if(x == 0 && y == 0 && z == 0) return dp[x][y][z] = 0;
int soma = x + y + z;
double convertido = (double)soma;
double tot = (N - soma)/convertido;
if(x != 0) tot += x*((solve(x-1,y,z) + 1)/convertido);
if(y != 0) tot += y*((solve(x+1,y-1,z) + 1)/convertido);
if(z != 0) tot += z*((solve(x,y+1,z-1) + 1)/convertido);
return dp[x][y][z] = tot;
}
int main(){
int a[4] = {0,0,0,0};
cin >> N;
for(int i = 1;i<=N;i++){
int x;
cin >> x;
a[x]++;
}
printf("%.9lf\n",solve(a[1],a[2],a[3]));
return 0;
}