codeforces 482c Game with Strings

网友投稿 586 2022-10-22

codeforces 482c Game with Strings

codeforces 482c Game with Strings

​​ 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 . 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. Input

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. Output

Print the single number — the expected value. Your answer will be considered correct if its absolute or relative error doesn’t exceed 10 - 9. Examples Input

2 aab aac

Output

2.000000000000000

Input

3 aaA aBa Caa

Output

1.666666666666667

Input

3 aca vac wqq

Output

1.000000000000000

Note

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 ;you guess the string in two questions. The event's probability is · = (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 ·· = ;

Thus, the expected value is equal to

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 .

In the third sample whatever position we ask about in the first question, we immediately identify the string.

我们设dp[s]表示在s状态下我有多少的可能不能够得到确切的答案 s中一表示我已经查过

首先预处理c数组 表示我已经询问了s状态的列 然后有多少个数组我已经区分开了

可以怎么求 我们可以先求相反的 设立d数组 表示 询问了s状态的列 但是我还有哪些位置无法区分

那么若一个状态无法区分 那么它的子集也一定无法区分

相当于每个都可以识别的状态都先打上标记 然后最后再下传标记即可

在算概率的时候 我新生成的状态tmp1=dp[s]/1-step 表示 在剩余没选的列中再选一列的概率是多少

然后 乘以我这次询问不可以确定的串的数量(c[next]-c[s])/not_done 就可以得出我下一个状态无法得到的概率 为了方便统计 把其加入p数组 最后统计出来 一起计算一下期望输出就好

#include#include#define S (1<<20)+10#define N1 55#define ll long long long long d[S],bin[N1];char str1[N1][N1];double p[22],dp[S];int n,c[S];inline int calc(ll s){ int cnt=0; while (s){if (s&1) cnt++;s>>=1;}return cnt;}int main(){ freopen("cf.in","r",stdin); scanf("%d",&n);if (n==1){printf("0");return 0;} for (int i=0;i

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:【对线面试官】如何实现去重和幂等
下一篇:hyperf 框架多 env 配置文件支持
相关文章

 发表评论

暂时没有评论,来抢沙发吧~