Test instructions: give n boxes. There are locks on every box. A key can only be opened with a lock, a lock has only one key. Of course, for some boxes that can't be opened with keys, we have to open them violently. Given the number of keys in each box and the specific ability to open that box, ask for the number of violent open boxes, so that all the boxes are opened.
Idea: Very much like the xiaodaobc of a certain way open the box problem. But because the problem is that each box will randomly put a key. This is expected to be a harmonic progression.
This problem is similar, we get first: violent open this box, can open those boxes. This can be done with Bitset for state compression.
Then, for each case, we consider how many ways, so that: violence to open certain cases, while opening the box. The expectation of violent opening of the box is the reciprocal of the number of programs. Then our expectation of each box is the sum of the expectations of the final opening of all boxes of violent open chests.
The code is as follows:
#include <cstdio> #include <bitset> #include <algorithm> #include <iostream> using namespace std
;
const int MAX = 1010;
int t,k,n,num;
Bitset<max> Key[max];
int main (void) {//freopen ("Input.txt", "R", stdin);
int cas = 1;
scanf ("%d", &t);
while (t--) {scanf ("%d", &n);
for (int i = 0; i < N; ++i) {key[i].reset ();
Key[i][i] = true;
} for (int i = 0; i < N; ++i) {scanf ("%d", &k);
for (int j = 0; j < K; ++j) {scanf ("%d", &num);
Key[i][num-1] = true;
}} for (int j = 0, J < N; ++j) for (int i = 0; i < n; ++i) if (Key[i][j])
Key[i] |= key[j];
Double ans = 0.0;
for (int j = 0; j < N; ++j) {int cnt = 0;
for (int i = 0; i < N; ++i) if (key[i][j]) cnt++; Ans + = 1.0/ Cnt
printf ("%f\n", ans);
} printf ("Case #%d:%.5f\n", Cas++,ans);
} return 0;
}