题意:给两个一样的只含有26个小写字母的字符串,然后两个分别做一下排列,问如果对应位置的字母相等那么就愉悦值就加一,问愉悦值的期望是多少?

题解:只考虑两个序列相对的位置,那么就相当于固定一个位置,另外一个序列做排列。对于一个字符,假设是a,然后a有Na个,那么a选第一个序列中a对应的位置,发生这个事件的概率为1*(n-1)!/n!,1是选那个位置,(n-1)!是其他的元素排列,n!是总的情况。(注意,不能因为a可以选多个点就乘上x,因为a不可能同时对应两个位置,所以对答案的贡献只有一次)

学习点:将问题拆分,一个一个考虑对答案的贡献值。

更新:学了概率论第一章以后来看这道题挺简单的,固定一个序列,另外一个序列的样本空间是序列的全排列n!,对于固定序列的i位置上的元素alpha(i),和它相等的事件有cnt[alpha(i)]*(n-1)!个。

答案是sigma(cnt[alpha(i)]*(n-1)!)/n! ,0< i<n-1,

#include<cstdio>
#include<cstring>
const int maxn = +;
char str[maxn];
typedef long long ll; ll cnt[]; int main()
{
scanf("%s",str);
for(char *p = str; *p ; p++){
cnt[*p]++;
}
ll ans = ;
int sum = ;
for(int i = 'a'; i <= 'z'; i++){
if(cnt[i]>){
sum += cnt[i];
ans += cnt[i]*cnt[i];
}
}
printf("%.15lf",(double)ans/sum);
return ;
}

CF Gym 100187B A Lot of Joy (古典概型)的更多相关文章

  1. python数学第四天【古典概型】

  2. 集训第六周 古典概型 期望 D题 Discovering Gold 期望

    Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell o ...

  3. 集训第六周 古典概型 期望 C题

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=30728 一个立体方块,每个单位方块都是关闭状态,每次任两个点,以这两点为对角 ...

  4. CF Gym 102028G Shortest Paths on Random Forests

    CF Gym 102028G Shortest Paths on Random Forests 抄题解×1 蒯板子真jir舒服. 构造生成函数,\(F(n)\)表示\(n\)个点的森林数量(本题都用E ...

  5. codeforces Gym 100187B B. A Lot of Joy

    B. A Lot of Joy Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/proble ...

  6. CF gym 101933 K King's Colors —— 二项式反演

    题目:http://codeforces.com/gym/101933/problem/K 其实每个点的颜色只要和父亲不一样即可: 所以至多 i 种颜色就是 \( i * (i-1)^{n-1} \) ...

  7. CF Gym 100463B Music Mess (思路)

    好题,当时想了半个小时,我往图论方面去想了,把出现过的字符串当场点,然后相互连边,那么就构成了一个三角形,一个大于三个点的连通分量里有以下结论:度为二的点可能是track,度为大于二的点一定不是tra ...

  8. cf Gym 101086M ACPC Headquarters : AASTMT (Stairway to Heaven)

    题目: Description standard input/output As most of you know, the Arab Academy for Science and Technolo ...

  9. CF Gym 100685A Ariel

    传送门 A. Ariel time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

随机推荐

  1. Google Analytics添加到网站

    把Google Analytics添加到网站的具体方式 https://developers.google.com/analytics/devguides/collection/analyticsjs ...

  2. C# 写 LeetCode easy #1 Two Sum

    1.Two Sum Given an array of integers, return indices of the two numbers such that they add up to a s ...

  3. 洛谷 - P2324 - 骑士精神 - A*搜索

    为什么估价是16,因为最后一步复原空格可以恢复两个位置,当然设成17.18都可以. #include<bits/stdc++.h> using namespace std; typedef ...

  4. Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key.

    Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key. 1.rea ...

  5. FZU 2218【状压】

    题意: 给出长为n的字符串,含有前k种小写字母,求两个不含重复元素的连续子串,使得他们的长度乘积最大. 思路: 字符种类16 ->(套路) 状压 暴力2000*2000得所有连续子串的长度,得每 ...

  6. 洛谷P3608 [USACO17JAN]Balanced Photo平衡的照片

    P3608 [USACO17JAN]Balanced Photo平衡的照片 题目描述 Farmer John is arranging his NN cows in a line to take a ...

  7. Sass 愿景

    在最近的一个 CSS 见面会上,我向与会者提问,“有人会在日常的工作流中使用 Sass 吗?”回答结果压倒性的表示肯定——保守谨慎地使用 Sass 已经成为过去式.Sass 正迅速成长为编写 CSS ...

  8. Luogu P2341 [HAOI2006]受欢迎的牛 SCC缩点

    把强连通分量缩点,如果有且仅有一个出度为0的强连通分量,那么答案就是他的size:如果有多个入度为0的,那么没有明星牛. #include<cstdio> #include<iost ...

  9. CodeForces - 1004A-Sonya and Hotels(思维)

    Sonya decided that having her own hotel business is the best way of earning money because she can pr ...

  10. 命令行 IRC 客户端 irssi 的基本操作

    登录与退出 启动 irssi $ irssi 登陆 IRC 服务器/connect server port 修改昵称/nick nickname 直接带昵称登录指定的服务器$ irssi -c [se ...