302497: CF482C. Game with Strings

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Game with Strings

题意翻译

你和你的朋友玩一个游戏,游戏规则如下。 你的朋友创造 n 个长度均为 m 的不相同的字符串,然后他随机地选择其中一个。他选择这些字符串的概率是相等的,也就是说,他选择 n 个字符串中的每一个的概率是 1/n 。你想猜猜你的朋友选择了哪个字符串。 为了猜到你的朋友选择了哪个字符串,你可以问他问题,形式如下:字符串中第 pos 个字符是什么?当问题的答案为唯一标识字符串时,我们认为这个字符串是猜测的。在字符串被猜测后,你将停止提问。 你没有一个特殊的策略,所以你每次可能会等概率的问任何一个你从没提过的位置。你的任务是确定你猜到你的朋友选的字符串所需次数的期望。 ##### 输入格式 第一行包括一个数字 n 。接下来 n 行,每行一个字符串,表示你朋友创造出的字符串。除此之外,所有字符的长度是相同的,在1~20之间。 ##### 输出格式 输出期望。答案保留九位小数。误差在10^-9以内.

题目描述

You play the game with your friend. The description of this game is listed below. Your friend creates $ n $ distinct strings of the same length $ m $ and tells you all the strings. Then he randomly chooses one of them. He chooses strings equiprobably, i.e. the probability of choosing each of the $ n $ strings equals ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF482C/cec343c6baaa60537c4b5905738b928218fa103b.png). You want to guess which string was chosen by your friend. In order to guess what string your friend has chosen, you are allowed to ask him questions. Each question has the following form: «What character stands on position $ pos $ in the string you have chosen?» A string is considered guessed when the answers to the given questions uniquely identify the string. After the string is guessed, you stop asking questions. You do not have a particular strategy, so as each question you equiprobably ask about a position that hasn't been yet mentioned. Your task is to determine the expected number of questions needed to guess the string chosen by your friend.

输入输出格式

输入格式


The first line contains a single integer $ n $ ( $ 1<=n<=50 $ ) — the number of strings your friend came up with. The next $ n $ lines contain the strings that your friend has created. It is guaranteed that all the strings are distinct and only consist of large and small English letters. Besides, the lengths of all strings are the same and are between $ 1 $ to $ 20 $ inclusive.

输出格式


Print the single number — the expected value. Your answer will be considered correct if its absolute or relative error doesn't exceed $ 10^{-9} $ .

输入输出样例

输入样例 #1

2
aab
aac

输出样例 #1

2.000000000000000

输入样例 #2

3
aaA
aBa
Caa

输出样例 #2

1.666666666666667

输入样例 #3

3
aca
vac
wqq

输出样例 #3

1.000000000000000

说明

In the first sample the strings only differ in the character in the third position. So only the following situations are possible: - you guess the string in one question. The event's probability is ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF482C/513b47d544fbfd2b63900943a3b125c3476d7507.png); - you guess the string in two questions. The event's probability is ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF482C/52f687c8c3ebad32aaf54f6658a640f43d093f4f.png) $ · $ ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF482C/c7153f63e3d01fc37aee4c4e23b360f1f43974ad.png) = ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF482C/513b47d544fbfd2b63900943a3b125c3476d7507.png) (as in this case the first question should ask about the position that is other than the third one); - you guess the string in three questions. The event's probability is ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF482C/52f687c8c3ebad32aaf54f6658a640f43d093f4f.png) $ · $ ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF482C/c7153f63e3d01fc37aee4c4e23b360f1f43974ad.png) $ · $ ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF482C/167351ebd6917ee61e9c20726ae6dbc47b94319a.png) = ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF482C/513b47d544fbfd2b63900943a3b125c3476d7507.png); Thus, the expected value is equal to ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF482C/df311d20e652e4c180fe1e82a15c664c3619e1a0.png) In the second sample we need at most two questions as any pair of questions uniquely identifies the string. So the expected number of questions is ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF482C/37a4409e8fd878cfcc15e4b3a111dbfc894bbb01.png). In the third sample whatever position we ask about in the first question, we immediately identify the string.

Input

题意翻译

你和你的朋友玩一个游戏,游戏规则如下。 你的朋友创造 n 个长度均为 m 的不相同的字符串,然后他随机地选择其中一个。他选择这些字符串的概率是相等的,也就是说,他选择 n 个字符串中的每一个的概率是 1/n 。你想猜猜你的朋友选择了哪个字符串。 为了猜到你的朋友选择了哪个字符串,你可以问他问题,形式如下:字符串中第 pos 个字符是什么?当问题的答案为唯一标识字符串时,我们认为这个字符串是猜测的。在字符串被猜测后,你将停止提问。 你没有一个特殊的策略,所以你每次可能会等概率的问任何一个你从没提过的位置。你的任务是确定你猜到你的朋友选的字符串所需次数的期望。 ##### 输入格式 第一行包括一个数字 n 。接下来 n 行,每行一个字符串,表示你朋友创造出的字符串。除此之外,所有字符的长度是相同的,在1~20之间。 ##### 输出格式 输出期望。答案保留九位小数。误差在10^-9以内.

加入题单

上一题 下一题 算法标签: