int eval(config v) { int sum; int E{0}; sum = accumulate(all(v),0); if (sum == 1) { if (v.back()==1) return 1; E = 1; } for (size_t i = 0; i < v.size(); i++) { if (v[i] == 0) continue; config w{v}; w[i]--; for (size_t j = i+1; j < w.size(); j++) w[j]++; int prob = (int) v[i] * inverse(sum); E = add(E, mult(eval(w), prob)); } return E; }
void visit(const config& v) { for (size_t i=0;i<v.size()-1;i++) cout << v[i] << ' '; cout << v.back() << ": " << eval(v) << endl; }