Language: C++


#include<bits/stdc++.h>
using namespace std;
double prob(double a, double b, double c, n, vector<vector<vector<double>>> &dp) {
	double ret{};
	if (a > 0) {
		//	ret += prob(a - 1, b, c) * transition of (a, b, c) to (a - 1, b, c)
		ret += prob(a - 1, b, c, n, dp) * (a / n);
	}
	if (b > 0) {
		//	ret += prob(a + 1, b - 1, c) * transition of (a, b, c) to (a + 1, b - 1, c)
		ret += prob(a + 1, b - 1, c, n, dp) * (b / n);
	}

	if (c > 0) {
		//	ret += prob(a, b + 1, c - 1) * transition of (a, b, c) to (a, b + 1, c - 1)
		ret += prob(a, b + 1, c - 1, n, dp) * (c / n);
	}
	if (a == 0 && b == 0 && c == 0) {
		return 1;
	}
	return dp[a][b][c] = ret;
}
int main() {
	double n;
	cin >> n;
	vector<int> v(n);
	double aa{}, bb{}, cc{};
	for (int i{}; i < n; i++) {
		cin >> v[i];
		if (v[i] == 1)a++;
		else if (v[i] == 2)b++;
		else c++;
	}
	vector<vector<vector<double>>> dp (a + 1, vector < vector<double>(b + 1, vector<double>(c + 1)));
	double dp[a + 1][b + 1][c + 1] {};
	return 1 / prob(a, b, c, n, dp);
}

Compiler output:
a.cc:4:43: error: 'n' has not been declared
    4 | double prob(double a, double b, double c, n, vector<vector<vector<double>>> &dp) {
      |                                           ^
a.cc: In function 'double prob(double, double, double, int, std::vector<std::vector<std::vector<double> > >&)':
a.cc:8:42: error: 'n' was not declared in this scope
    8 |                 ret += prob(a - 1, b, c, n, dp) * (a / n);
      |                                          ^
a.cc:12:46: error: 'n' was not declared in this scope
   12 |                 ret += prob(a + 1, b - 1, c, n, dp) * (b / n);
      |                                              ^
a.cc:17:46: error: 'n' was not declared in this scope
   17 |                 ret += prob(a, b + 1, c - 1, n, dp) * (c / n);
      |                                              ^
a.cc: In function 'int main()':
a.cc:31:31: error: 'a' was not declared in this scope
   31 |                 if (v[i] == 1)a++;
      |                               ^
a.cc:32:36: error: 'b' was not declared in this scope
   32 |                 else if (v[i] == 2)b++;
      |                                    ^
a.cc:33:22: error: 'c' was not declared in this scope
   33 |                 else c++;
      |                      ^
a.cc:35:44: error: 'a' was not declared in this scope; did you mean 'aa'?
   35 |         vector<vector<vector<double>>> dp (a + 1, vector < vector<double>(b + 1, vector<double>(c + 1)));
      |                                            ^
      |                                            aa
a.cc:35:75: error: 'b' was not declared in this scope; did you mean 'bb'?
   35 |         vector<vector<vector<double>>> dp (a + 1, vector < vector<double>(b + 1, vector<double>(c + 1)));
      |                                                                           ^
      |                                                                           bb
a.cc:35:97: error: 'c' was not declared in this scope; did you mean 'cc'?
   35 |         vector<vector<vector<double>>> dp (a + 1, vector < vector<double>(b + 1, vector<double>(c + 1)));
      |                                                                                                 ^
      |                                                                                                 cc
a.cc:35:103: error: template argument 1 is invalid
   35 |         vector<vector<vector<double>>> dp (a + 1, vector < vector<double>(b + 1, vector<double>(c + 1)));
      |                                                                                                       ^
a.cc:35:103: error: template argument 2 is invalid