#include #include #include #include #include using namespace std; int nType, totalCard; vector init; void read() { init = vector(4, 0); cin >> nType; for (int i = 0; i < nType; ++i) { int cnt; cin >> cnt; ++init[min(3, cnt)]; } totalCard = accumulate(init.begin(), init.end(), 0); } double rec(vector &num2cnt, map, double> &dp) { if (num2cnt[3] == nType) return 0; if (dp.count(num2cnt)) return dp[num2cnt]; double sum = 1; for (int i = 0; i < 3; ++i) { if (num2cnt[i] > 0) { double mul = 1.0 * num2cnt[i] / totalCard; --num2cnt[i]; ++num2cnt[i + 1]; sum += rec(num2cnt, dp) * mul; ++num2cnt[i]; --num2cnt[i + 1]; } } return dp[num2cnt] = sum / (1 - 1.0 * num2cnt[3] / totalCard); } void work() { map, double> dp; printf("%.10lf\n", rec(init, dp)); } int main() { read(); work(); return 0; }