The brumpy's colony
Difficulty: Hard

The scientists have discovered a new animal specie, the brumpies. This new specie is very funny and interesting. The scientists now are experimenting with their reproduction. This specie has asexual reproduction, which means they do not need a couple for the reproduction .T hey reproduce themselves by division. It has been discovered N different types of this specie. 

The moment of the reproduction is very interesting. When the brumpies try to reproduce, it has the same probability of reproducing or dying. If it reproduces, a new brumpy is born but if the new brumpy is the same type as is father, the father must abandon the colony. Each colony will just have one reproduction per day and will just involve one brumpy. Strange, isn't it? If there is just one brumpy at the colony , it will never die when it is reproducing. The colony never disappears. 

All the brumpies have the same probability of being selected on the colony for the reproduction into the current day. 

The scientists are interested in this reproduction process so they want to know the expected number of days for an 
initial colony to become a colony with all the N brumpy's types present. 


**Input specification**

The first line contains N (1 <= N <= 8) - How many types of brumpy exist. The second line contains the
description of the initial colony. It starts with A(1 <= A <= N), how many brumpies there are. Follow A distinct
integers Ai(1 <= Ai <= N), the types of brumpies present in the initial colony. Next, follow N lines with N integers 
Pij(1 <= Pij <= 100) for each line. Pij means the probability multiplied by 100 of obtaining a brumpy type-j when
a type-i is reproducing. This table is consistent, that means the summation of each row is 100.

**Output specification**

Just a simple line, the expected numbers of days for the initial colony to become a colony with all the N brumpy's
types present rounded up to 2 decimal places.


**Sample input**
<br>2
<br>1 2
<br>34 66
<br>29 71

**Sample output**
<br>3.45

Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (Python):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;



public class Main {
	
	static int N, A;
	static int INITIAL=0;
	static double P[][];
	static String cad[];
	static double M[][];
		
	static String Round(double sol) {
		sol = Math.round(sol * 100.0) / 100.0;
		DecimalFormat format = new DecimalFormat("0.00");
		DecimalFormatSymbols dfs = format.getDecimalFormatSymbols();
		dfs.setDecimalSeparator('.');
		format.setDecimalFormatSymbols(dfs);
	
		return format.format(sol);
	}
	
	static void Gauss(int n){
		for(int col = 0;col < n;col++){
			int piv = col;
			for(int row = col + 1; row < n;row++)
				if(Math.abs(M[row][col]) > Math.abs(M[piv][col]))
						piv = row;			
			for(int k = 0;k<=n;k++) {
				double tmp = M[col][k];
				M[col][k] = M[piv][k];
				M[piv][k] = tmp;				
			}			
			for(int row = col + 1;row < n;row++){
				double m = M[row][col] / M[col][col];
				for(int k = col;k<=n;k++)
					M[row][k] -= m * M[col][k];
				}
			}
			//inverse process
			for(int row = n-1;row >= 0 ;row--){
				for(int col = row + 1;col <n;col++)
					M[row][n] -= M[row][col] * M[col][n];
				M[row][n] /= M[row][row];
		}
	}
		
	public static void main(String[] args) throws IOException {
		InputStreamReader sr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(sr);
				
		N = Integer.parseInt(br.readLine());
		
		cad = br.readLine().split(" ");		
		A = Integer.parseInt(cad[0]);
		for(int i = 1;i<=A;i++) {
			INITIAL |= 1<<(Integer.parseInt(cad[i])-1);
		}		
	
		P = new double[N+1][N+1];
				
		for(int i = 0;i<N;i++) {
			cad = br.readLine().split(" ");
			for(int j = 0;j<N;j++) {
				P[i][j] = Double.parseDouble(cad[j]) / 100.0;
			}
		}		
		
		M = new double[(1<<N)+5][(1<<N)+5];
		
		for(int i = 1;i<(1<<N)-1;i++) {
			int cc = 0;
			for(int j = 0;j<N;j++)
				if((i & (1<<j))>0) 
					++cc;				
			
			for(int j = 0;j<N;j++)
				if((i & (1<<j))>0) {
					double rep = (cc == 1 ? 1.0 : 0.5);
					for(int k = 0;k<N;k++){
						M[i-1][ (i | (1<<k)) - 1] -= (1.0/(double)cc) * rep * P[j][k];
					}
					
					if(cc>1)
						M[i-1][ (i ^ (1<<j)) - 1] -= (1.0/(double)cc) * 0.5;
				}
			
			M[i-1][i-1] += 1.0;
			M[i-1][(1<<N)-1] = 1;
		}	
		
		M[(1<<N)-2][(1<<N)-2] = 1;
		M[(1<<N)-2][(1<<N)-1] = 0;
		
		Gauss((1<<N)-1);		

		System.out.println(Round(M[INITIAL-1][(1<<N)-1]));
	}
}