CF482C Game with Strings

题目描述

你和你的朋友玩一个游戏,游戏规则如下。 你的朋友创造出了 $n$ 个长度均为 $m$ 的不相同的字符串,然后他随机地选择其中一个。他选择这些字符串的概率是相等的,也就是说,他选择 $n$ 个字符串中的每一个的概率是 $\frac{1}{n}$。你想猜猜你的朋友选择了哪个字符串。 为了猜到你的朋友选择了哪个字符串,你可以问他问题,形式如下:字符串中第 $pos$ 个字符是什么?当这些问题的答案能够唯一确定一个字符串时,我们认为这个字符串被猜到了。在字符串被猜到后,你将停止提问。 你没有特殊的策略,所以你每次可能会等概率的问任何一个你从没猜过的位置。求猜到你的朋友选的字符串所需次数的期望。

输入格式

输出格式

说明/提示

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.