Language: C++

//#include<bits/stdc++.h>
using namespace std;

using ll = long long;

//constant
const ll MOD = 1e+9 + 7;
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

vector<vector<vector<double>>> dp;
int N;

double rec(int i, int j, int k) {
	if (dp[i][j][k] >= 0) return dp[i][j][k];
	if (i == 0 && j == 0 && k == 0) return 0;

	double res = 0.0;
	if (i > 0) res += rec(i-1, j, k) * i;
	if (j > 0) res += rec(i+1, j-1, k) * j;
	if (k > 0) res += rec(i, j+1, k-1) * k;
	res += N;
	res /= (i + j + k);

	return dp[i][j][k] = res;
}


int main(void) {

	cin >> N;

	vector<int> state(3);
	
	int num;
	REP(i, N) {
		cin >> num;
		state[num - 1]++;
	}

	int I, J, K;
	I = state[0];
	J = state[1];
	K = state[2];

	dp.assign(N+1, vector<vector<double>>(N+1, vector<double>(N+1, -1)));
	dp[1][0][0] = N;

	cout << setprecision(10) <<rec(I, J, K) << endl;

	return 0;
}

Compiler output:
a.cc: In function 'void view(T)':
a.cc:20:44: error: 'cout' is not a member of 'std'
   20 | template<typename T> void view(T e) { std::cout << e << std::endl; }
      |                                            ^~~~
a.cc:1:1: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | //#include<bits/stdc++.h>
a.cc:20:62: error: 'endl' is not a member of 'std'
   20 | template<typename T> void view(T e) { std::cout << e << std::endl; }
      |                                                              ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | //#include<bits/stdc++.h>
a.cc: At global scope:
a.cc:21:43: error: 'vector' in namespace 'std' does not name a template type
   21 | template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
      |                                           ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | //#include<bits/stdc++.h>
a.cc:21:49: error: expected ',' or '...' before '<' token
   21 | template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
      |                                                 ^
a.cc: In function 'void view(int)':
a.cc:21:80: error: 'v' was not declared in this scope
   21 | template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
      |                                                                                ^
a.cc:21:90: error: 'cout' is not a member of 'std'
   21 | template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
      |                                                                                          ^~~~
a.cc:21:90: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:21:115: error: 'cout' is not a member of 'std'
   21 | template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
      |                                                                                                                   ^~~~
a.cc:21:115: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:21:128: error: 'endl' is not a member of 'std'
   21 | template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
      |                                                                                                                                ^~~~
a.cc:21:128: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc: At global scope:
a.cc:22:43: error: 'vector' in namespace 'std' does not name a template type
   22 | template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }
      |                                           ^~~~~~
a.cc:22:38: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
   22 | template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }
      |                                      ^~~
a.cc:22:49: error: expected ',' or '...' before '<' token
   22 | template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }
      |                                                 ^
a.cc:22:27: error: redefinition of 'template<class T> void view(int)'
   22 | template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }
      |                           ^~~~
a.cc:21:27: note: 'template<class T> void view(int)' previously declared here
   21 | template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
      |                           ^~~~
a.cc:28:1: error: 'vector' does not name a type
   28 | vector<vector<vector<double>>> dp;
      | ^~~~~~
a.cc: In function 'double rec(int, int, int)':
a.cc:32:13: error: 'dp' was not declared in this scope
   32 |         if (dp[i][j][k] >= 0) return dp[i][j][k];
      |             ^~
a.cc:42:16: error: 'dp' was not declared in this scope
   42 |         return dp[i][j][k] = res;
      |                ^~
a.cc: In function 'int main()':
a.cc:48:9: error: 'cin' was not declared in this scope
   48 |         cin >> N;
      |         ^~~
a.cc:48:9: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:50:9: error: 'vector' was not declared in this scope
   50 |         vector<int> state(3);
      |         ^~~~~~
a.cc:50:9: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:50:16: error: expected primary-expression before 'int'
   50 |         vector<int> state(3);
      |                ^~~
a.cc:55:17: error: 'state' was not declared in this scope; did you mean 'static'?
   55 |                 state[num - 1]++;
      |                 ^~~~~
      |                 static
a.cc:59:13: error: 'state' was not declared in this scope; did you mean 'static'?
   59 |         I = state[0];
      |             ^~~~~
      |             static
a.cc:63:9: error: 'dp' was not declared in this scope
   63 |         dp.assign(N+1, vector<vector<double>>(N+1, vector<double>(N+1, -1)));
      |         ^~
a.cc:63:38: error: expected primary-expression before 'double'
   63 |         dp.assign(N+1, vector<vector<double>>(N+1, vector<double>(N+1, -1)));
      |                                      ^~~~~~
a.cc:66:9: error: 'cout' was not declared in this scope
   66 |         cout << setprecision(10) <<rec(I, J, K) << endl;
      |         ^~~~
a.cc:66:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:66:17: error: 'setprecision' was not declared in this scope
   66 |         cout << setprecision(10) <<rec(I, J, K) << endl;
      |                 ^~~~~~~~~~~~
a.cc:1:1: note: 'std::setprecision' is defined in header '<iomanip>'; this is probably fixable by adding '#include <iomanip>'
  +++ |+#include <iomanip>
    1 | //#include<bits/stdc++.h>
a.cc:66:52: error: 'endl' was not declared in this scope
   66 |         cout << setprecision(10) <<rec(I, J, K) << endl;
      |                                                    ^~~~
a.cc:66:52: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'