题意:有$n$个孩子,第$i$个孩子有$k[i]$件想要的礼物,第$j$个礼物为$a[i][j]$,现在随机挑一个孩子,从他想要的礼物里面随机挑一个,然后送给另一个孩子$($这个孩子可以和第一个孩子是同一个人$)$,问你送的这个礼物在后一个孩子愿望单里的概率。

思路:求出每件礼物出现的次数$cnt[]$,挑出第一个孩子的概率为$\frac{1}{n}$,在他的愿望单里挑出一件礼物的概率为$\frac{1}{k[i]}$,挑出另一个孩子的概率也是$\frac{1}{n}$,挑出的第一个孩子的每件礼物$a[i][j]$出现了$cnt[a[i][j]]$次,那么对于第$i$个孩子的第$j$件礼物$a[i][j]$礼物而言,对答案的贡献就是$\frac{cnt[a[i][j]]}{n^{2}*k[i]}$,所以总概率$$p=\sum_{i=1}^{n}\sum_{j=1}^{k[i]}\frac{cnt[a[i][j]]}{n^{2}*k[i]}$$用快速幂取逆元。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector> using namespace std; typedef long long ll; const int N = ;
const ll mod = ; ll n, k[N], s[N], cnt[N];
vector<ll> v[N]; ll power(ll a, ll n, ll p)
{
ll ba = a, res = ;
while (n) {
if ( == n % ) res = (res * a) % p;
a = (a * a) % p, n /= ;
}
return res;
} int main()
{
scanf("%lld", &n);
for (int i = ; i <= n; i++) {
scanf("%lld", &k[i]);
for (int j = ; j <= k[i]; j++) {
ll a;
scanf("%lld", &a);
cnt[a]++, v[i].push_back(a);
}
}
for (int i = ; i <= n; i++) {
for (int j = ; j < k[i]; j++) s[i] += cnt[v[i][j]];
}
ll res = ;
for (int i = ; i <= n; i++) {
ll tp = ((n * n) % mod * k[i] % mod) % mod;
ll inv = power(tp, mod - , mod);
res = (res + (s[i] * inv) % mod) % mod;
}
printf("%lld\n", res);
return ;
}

Educational Codeforces Round 79 (Rated for Div. 2) - D. Santa's Bot(数论)的更多相关文章

  1. Educational Codeforces Round 79 (Rated for Div. 2) Finished (A-D)

    如果最大值比剩余两个加起来的总和+1还大,就是NO,否则是YES #include<bits/stdc++.h> using namespace std; int main(){ int ...

  2. CF codeforces A. New Year Garland【Educational Codeforces Round 79 (Rated for Div. 2)】

    A. New Year Garland time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Educational Codeforces Round 88 (Rated for Div. 2) E. Modular Stability(数论)

    题目链接:https://codeforces.com/contest/1359/problem/E 题意 有一大小为 $k$ 的数组,每个元素的值在 $[1,n]$ 间,若元素间两两不等,问有多少数 ...

  4. Educational Codeforces Round 39 (Rated for Div. 2) B. Weird Subtraction Process[数论/欧几里得算法]

    https://zh.wikipedia.org/wiki/%E8%BC%BE%E8%BD%89%E7%9B%B8%E9%99%A4%E6%B3%95 取模也是一样的,就当多减几次. 在欧几里得最初的 ...

  5. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  6. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  7. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  8. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  9. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

随机推荐

  1. EQ实现

    原理参考: https://www.cnblogs.com/fellow1988/p/9189338.html https://www.cnblogs.com/fellow1988/p/9136346 ...

  2. Nginx之server和location配置使用

    配置server代码段: server { server_name www.meiduo.site; listen ; root /home/python/Desktop/meiduo_mall_ad ...

  3. Bugku-CTF分析篇-weblogic(黑客攻击了Weblogic应用,请分析攻击过程,找出Weblogic的主机名。)

    weblogic 黑客攻击了Weblogic应用,请分析攻击过程,找出Weblogic的主机名. flag格式:flag{} Tip:主机名为十六进制.  

  4. Bugku-CTF加密篇之来自宇宙的信号(银河战队出击)

    来自宇宙的信号 银河战队出击 flag格式 flag{字母小写}    

  5. Atcoder Beginner Contest 147C(状态压缩)

    最多15个人,用N个二进制的数字表示每个人的状态,然后检验.这串数字相当于已经把这些人的状态定了下来,如果和输入的情况不符则这串数字不正确,直接忽略,因为枚举了所有的情况,所以总有正确的,不必在错误的 ...

  6. 远程传输文件命令:scp

    1.概述 scp(secure copy)是一个基于 SSH 协议在网络之间进行安全传输的命令,其格式为“scp [参数] 本地文件 远程帐户@远程 IP 地址:远程目录”. 与第 2 章讲解的 cp ...

  7. 总结fiddler抓https包

    把fiddler工具>选项>https>勾选所有,点击actions,导出的证书导入到浏览器(打开右上角浏览器设置>选项>高级>证书>查看证书>证书机构 ...

  8. Unknown failure (Failure - not installed for 0) 、Error while Installing APKs

    解决方法一: 设置 -> 更多设置 -> 开发者选项 ->关闭启用MIUI优化 解决方法二:(这种方法就用不了apply changes的功能了) 描述:在一些机型上安装软件 提示卸 ...

  9. frp 使用基础笔记

    0x01 简介 为什么需要内网穿透? 很多时候从公网访问自己内网的设备是困难的,毕竟自己没有一个独立的IP地址. Frp 服务器进行内网穿透,速度快还十分简单.可以实现很多功能,包括不限于远程桌面,文 ...

  10. 查看svn 提交记录

    svn log -v -r {2019-8-11}:{2019-8-16} -l 30 | sed -n '/wangyue01/,/--$/ p'其中:-r {2018-9-10}:{2018-9- ...