Metro quiz

시간 제한5초메모리 제한1024 MB

요약
M개 역에 대한 N개 노선의 정차역 집합이 주어질 때, 균등하게 선택된 노선을 알아내기 위한 최소 기대 질문 수를 구하고, 불가능하면 not possible을 출력한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 비트 연산, 그리디, 조합론
정답자
아직 제출이 없습니다

문제

Two Olympics spectators are waiting in a queue. They each hold a copy of the metro map of Paris, and they devised a little game to kill time. First, player A thinks of a metro line (chosen uniformly at random among all metro lines) that player B will need to guess. In order to guess, player B repeatedly asks whether the line stops at a metro station of her choice, and player A answers truthfully. After enough questions, player B will typically know with certainty which metro line player A had in mind. Of course, player B wants to minimise the number of questions she needs to ask.

You are given the map of the NN metro lines (numbered from 11 to NN), featuring a total of MM metro stations (numbered from 00 to M−1M - 1) and indicating, for each line, those stations at which the line stops. Please compute the expected number of questions that player B needs to ask to find the answer, in the optimal strategy.

In other words, given a strategy SS, note Q_S,jQ\_{S,j} the number of questions asked by the strategy if the metro line in the solution is line jj. Then, note

E_S=E\[Q_S]=1N∑_j=1NQ_S,jE\_S = \mathbb{E}\[Q\_S] = \frac{1}{N}\sum\_{j=1}^{N}{Q\_{S,j}}

the expected value of Q_S,jQ\_{S,j} assuming that jj is uniformly chosen from the set of all metro lines. Your task is to compute min⁡_S\min\_S E_SE\_S.

If it is not always possible for player B to know which line player A had in mind with certainty, output not possible.

입력

The first line contains the number NN. The second line contains the number MM. Then follow MM lines: the kkth such line contains first a positive integer n≤Nn \le N, then a space, and then nn space-separated integers s_1,s_2,…,s_ns\_1,s\_2, \dots ,s\_n; these are the metro stations at which line kk stops. A line stops at a given station at most once.

출력

The output should contain a single line, consisting of a single number: the minimum expected number of questions that player B must ask in order to find the correct metro line, or not possible (in lowercase characters). Answers within 10−410^{-4} of the correct answer will be accepted.

제한

  • 1≤N≤181 \le N \le 18
  • 1≤M≤501 \le M \le 50

예제2

  1. 예제 1

    입력
    5
    4
    3 0 3 4
    3 0 2 3
    3 2 3 4
    2 1 2
    
    예상 출력
    2
    
  2. 예제 2

    입력
    3
    3
    1 0
    1 1
    1 2
    
    예상 출력
    1.66666666666667