Codeforces 16E Fish - Problem Statement

CF 16E - probability bitmask DP

There are nn fish in a lake. Each second, two fish meet uniformly at random, and one eats the other. You're given a matrix where a[i][j]a[i][j] is the probability that fish ii eats fish jj when they meet.

Find the probability that each fish is the last survivor. Output nn probabilities.

Constraints: n18n \le 18. This hints at bitmask DP since 2182^{18} states are manageable.

Simulating all meeting sequences grows factorially. Instead, track the set of surviving fish as state since transitions only depend on which fish remain.