Language: C++

#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (int) (k); ++i)
#define Rep(i, j, k) for(R int i = (j); i >= (int) (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 311;
const ll INF = 5e16;

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread(buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		R ll x = 0; R int f = 0; R char dd;
		for (; !isdigit(ch); dd) f ^= (ch == '-');
		for (; isdigit(ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) x = -x, putchar('-');
		if (x > 9) write(x / 10); putchar(x % 10 | 48);
	}

	inline void wrn ( ll x ) { write(x), putchar(' '); }

	inline void wln ( ll x ) { write(x), putchar('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x), wln(y); }

}

using IO::wln;
using IO::read;

namespace Cesare {
	
	/*
		一个 a[i] 被删到 0 需要选他 a[i] 次 
		f[i][j][k] 表示从 (a1, a2, a3) 删到 (i, j, k)
		的期望操作次数。 
	*/
	
	ll a1, a2, a3;
	ll n, S = 0, a[N];
	double Ans, f[N][N][N];
	
	inline double dfs ( ll x, ll y, ll z ) {
		if (f[x][y][z]) return f[x][y][z];
		if (x == 0 && y == 0 && z == 0) return 0;
		
		double res =  = 1;
		if (x) res += dfs(x - 1, y, z) * x / (x + y + z);
		if (y) res += dfs(x + 1, y - 1, z) * y / (x + y + z);
		if (z) res += dfs(x, y + 1, z - 1) * z / (x + y + z);
		res += 1.0 * (n - x - y - z) / (x + y + z);
		return f[x][y][z] = res;
	}
	
//	inline double dfs ( ll x, ll y, ll z ) {
//		if (f[x][y][z]) return f[x][y][z];
//		if (x == a1 && y == a2 && z == a3) return 0;
//		
//		double res = 1.0 / (n - x - y - z);
//		if (x < a1) res += dfs(x + 1, y, z) * (a1 - x) / (n - x - y - z);
//		if (x && y < a2) res += dfs(x - 1, y + 1, z) * (a2 - y) / (n - x - y - z);
//		if (y && z < a3) res += dfs(x, y - 1, z + 1) * (a3 - z) / (n - x - y - z);
//		if (n > 1) res += 1.0 * (x + y + z) / (n - 1);
//		
//		return f[x][y][z] = res;
//	}
	
	int main() {
		n = read();
		For ( i, 1, n ) a[i] = read();
		For ( i, 1, n ) 
			a1 += a[i] == 1, 
			a2 += a[i] == 2, a3 += a[i] == 3;
		dfs(a1, a2, a3);
//		if (n > 1) f[a1][a2][a3] += 1.0 * n / (n - 1);
		return printf("%.8lf\n", f[a1][a2][a3]), 0;
	}
	
}

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);

	return Cesare :: main();
}

/*

*/






Compiler output:
a.cc: In function 'll IO::read()':
a.cc:27:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   27 |                 R ll x = 0; R int f = 0; R char dd;
      |                      ^
a.cc:27:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   27 |                 R ll x = 0; R int f = 0; R char dd;
      |                                   ^
a.cc:25:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   25 |         #define dd ch = getchar()
      |                    ^~
a.cc:27:49: note: in expansion of macro 'dd'
   27 |                 R ll x = 0; R int f = 0; R char dd;
      |                                                 ^~
a.cc: In function 'double Cesare::dfs(ll, ll, ll)':
a.cc:66:31: error: expected primary-expression before '=' token
   66 |                 double res =  = 1;
      |                               ^
a.cc: In function 'int Cesare::main()':
a.cc:89:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   89 |                 For ( i, 1, n ) a[i] = read();
      |                       ^
a.cc:9:32: note: in definition of macro 'For'
    9 | #define For(i, j, k) for(R int i = (j); i <= (int) (k); ++i)
      |                                ^
a.cc:90:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   90 |                 For ( i, 1, n )
      |                       ^
a.cc:9:32: note: in definition of macro 'For'
    9 | #define For(i, j, k) for(R int i = (j); i <= (int) (k); ++i)
      |                                ^