XSY contest1586 proB
题目
现在一圈n个花坛, 每次随机往一个花盆里种花, 一个花盆可以种多颗花, 假如一个花盆两边的花盆都有花, 那么他也将被种上花
问期望种满所有花盆要种几次
首先定义f(i)为放置了i个物品后完全覆盖的概率, 可以发现
\]
- 那么答案就是$$\sum_{i=0}^{n - 1}(1 - f[i]) \frac{n}{n - i}$$
- On了
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#define ll long long
#define M 10000100
#define mmp make_pair
using namespace std;
int read() {
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
}
int fac[M], inv[M], n;
const int mod = 1000000007;
void add(int &x, int y) {
x += y;
x -= x >= mod ? mod : 0;
}
int mul(int a, int b) {
return 1ll * a * b % mod;
}
int poww(int a, int b) {
int ans = 1, tmp = a;
for(; b; b >>= 1, tmp = mul(tmp, tmp)) if(b & 1) ans = mul(ans, tmp);
return ans;
}
int C(int n, int m)
{
if(m > n || n < 0 || m < 0) return 0;
return mul(fac[n], mul(inv[m], inv[n - m]));
}
int Inv(int x) {
return mul(inv[x], fac[x - 1]);
}
int invC(int n, int m)
{
return mul(inv[n], mul(fac[m], fac[n - m]));
}
int f(int i)
{
return (1 - mul(C(i, n - i), invC(n - 1, i - 1)) + mod) % mod;
}
int main() {
n = read();
fac[0] = inv[0] = 1;
for(int i = 1; i <= n; i++) fac[i] = mul(fac[i - 1], i);
inv[n] = poww(fac[n], mod - 2);
for(int i = n - 1; i >= 1; i--) inv[i] = mul(inv[i + 1], i + 1);
int ans = 0;
for(int i = 0; i < n; i++) add(ans, mul(mul(n, Inv(n - i)), f(i)));
cout << ans << "\n";
return 0;
}
XSY contest1586 proB的更多相关文章
- Could not autowire. No beans of 'TbItemMapper' type found. less... (Ctrl+F1) Checks autowiring prob
Intellij Idea开发工具在@Autowired或者@Resource注入XxxMapper接口时报如下错误: Could not autowire. No beans of 'TbItemM ...
- soj1022. Poor contestant Prob
1022. Poor contestant Prob Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description As everyb ...
- prob
void calc_probability(int num) { , j = , k = ; #define SIZE_NUM 8 int *array_num = NULL; int *rememb ...
- NOIP 2011 Day 1 部分题解 (Prob#1 and Prob#2)
Problem 1: 铺地毯 乍一看吓cry,地毯覆盖...好像是2-dims 线段树,刚开头就这么难,再一看,只要求求出一个点,果断水题,模拟即可.(注意从标号大的往小的枚举,只要有一块地毯符合要求 ...
- The `XXXX` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-game-desktop/Pods-game-desktop.release.xcconfig'. This can lead to prob
The `game-desktop [Release]` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Po ...
- 【AIM Tech Round 4 (Div. 2) D Prob】
·题目:D. Interactive LowerBound ·英文题,述大意: 有一个长度为n(n<=50000)的单链表,里面的元素是递增的.链表存储在一个数组里面,给出长度n.表 ...
- 1.1.5 PROB Friday the Thirteenth
Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does the 13th of the mont ...
- 1.1.4 PROB Greedy Gift Givers
Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...
- 1.1.1 PROB Your Ride Is Here
=== /* ID: luopengting PROG: ride LANG: C++ */ #include <iostream> #include <cstdio> #in ...
随机推荐
- python之路---模块
在python中,为了简少代码重复量,我们将引用了函数,面向对象 等方法.为了能够让这些函数,面向对象可以再其他python文件中引用,我们将功能函数写在一个py文件中,该py文件即是一个模块,可以共 ...
- Andriod Studio两种签名机制V1和V2的区别
Android Studio 2.2以上版本打包apk的时候,我们会发现多了个签名版本(v1.v2)选择,如下图红色方框所示 问题描述(v1和v2) Android 7.0中引入了APK Signat ...
- Linux防火墙iptables的基础
一.网络访问控制 1.Linux一般都是作为服务器系统使用,对外提供一些基于网络的服务 2.通常我们都需要对服务器进行一些网络访问控制,类似防火墙的功能 3.常见的访问控制包括:哪些IP可以访问服务器 ...
- 【转】python 中NumPy和Pandas工具包中的函数使用笔记(方便自己查找)
二.常用库 1.NumPy NumPy是高性能科学计算和数据分析的基础包.部分功能如下: ndarray, 具有矢量算术运算和复杂广播能力的快速且节省空间的多维数组. 用于对整组数据进行快速运算的标准 ...
- tensorboard使用方法
http://blog.csdn.net/u010099080/article/details/77426577
- oracle数据库SQL入门
1.oracle数据库的下载.安装.卸载 Oracle下载: Oracle下载链接地址:http://www.oracle.com/technetwork/cn/database/enterprise ...
- 用matlab生成mif文件
在FPGA中,rom模块的初始化文件分为两种,一种是hex文件,另外一种是mif文件,这两种文件都可以通过Quartus进行手工创建,进行手工输入数据,也可以借助于专用的文件编辑器完成编辑. 在此介绍 ...
- 一、JAVA变量类型:①类变量与实例变量的异同点
在JAVA中,变量使用前必须声明,格式如下: int a; //单个变量声明 int b, c, d; //多个变量一起声明 int e = 1, f = 2, g = 3; //声明时同时赋值(初始 ...
- windows环境搭建Vue开发环境
一.安装node.js(https://nodejs.org/en/) 下载完毕后,可以安装node,建议不要安装在系统盘(如C:). 二.设置nodejs prefix(全局)和cache(缓存)路 ...
- 奇异值分解(SVD)与在降维中的应用
奇异值分解(Singular Value Decomposition,SVD)是在机器学习领域广泛应用的算法,它不光可以用于降维算法中的特征分解,还可以用于推荐系统,以及自然语言处理等领域.是很多机器 ...