题目
  • 现在一圈n个花坛, 每次随机往一个花盆里种花, 一个花盆可以种多颗花, 假如一个花盆两边的花盆都有花, 那么他也将被种上花

  • 问期望种满所有花盆要种几次

  • 首先定义f(i)为放置了i个物品后完全覆盖的概率, 可以发现

\[f[i] = \frac{C_i^{n-i}}{C_{n - 1}^{i - 1}}
\]

  • 那么答案就是$$\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的更多相关文章

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

  2. soj1022. Poor contestant Prob

    1022. Poor contestant Prob Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description As everyb ...

  3. prob

    void calc_probability(int num) { , j = , k = ; #define SIZE_NUM 8 int *array_num = NULL; int *rememb ...

  4. NOIP 2011 Day 1 部分题解 (Prob#1 and Prob#2)

    Problem 1: 铺地毯 乍一看吓cry,地毯覆盖...好像是2-dims 线段树,刚开头就这么难,再一看,只要求求出一个点,果断水题,模拟即可.(注意从标号大的往小的枚举,只要有一块地毯符合要求 ...

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

  6. 【AIM Tech Round 4 (Div. 2) D Prob】

    ·题目:D. Interactive LowerBound ·英文题,述大意:       有一个长度为n(n<=50000)的单链表,里面的元素是递增的.链表存储在一个数组里面,给出长度n.表 ...

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

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

  9. 1.1.1 PROB Your Ride Is Here

    === /* ID: luopengting PROG: ride LANG: C++ */ #include <iostream> #include <cstdio> #in ...

随机推荐

  1. django中的ORM介绍和字段及字段参数

    Object Relational Mapping(ORM) ORM介绍 ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据 ...

  2. python之路-----多线程与多进程

    一.进程和线程的概念 1.进程(最小的资源单位): 进程:就是一个程序在一个数据集上的一次动态执行过程.进程一般由程序.数据集.进程控制块三部分组成. 程序:我们编写的程序用来描述进程要完成哪些功能以 ...

  3. 【转载】GET和POST两种基本请求方法的区别

    原文地址:http://www.cnblogs.com/logsharing/p/8448446.html GET和POST是HTTP请求的两种基本方法,要说它们的区别,接触过WEB开发的人都能说出一 ...

  4. redis-cluster配置

    为什么要用redis-cluster 1.并发问题 redis官方生成可以达到 10万/每秒,每秒执行10万条命令假如业务需要每秒100万的命令执行呢? 2.数据量太大 一台服务器内存正常是16~25 ...

  5. Discuz!安装搭建

    Discuz!介绍 Discuz!是一款由php语言开发的论坛源代码包,运行在lamp平之上或者lnmp之上,点击此处打开官方网站 环境介绍 本次安装采用最简配置,全部用yum安装,php采用模块方式 ...

  6. linux远程管理常用命令

    目标 关机/重启 shutdown 查看或配置网卡信息 ifconfig ping 远程登录和复制文件 ssh scp 01. 关机/重启 序号 命令 对应英文 作用 01 shutdown 选项 时 ...

  7. VS--------实用快捷键

    Ctrl + M + O : 折叠所有方法 Ctrl + Tab: 切换不同窗口 ------------------------------开发--------------------------- ...

  8. springcloud Eureka学习笔记

    最近在学习springcloud,抽空记录下学习笔记;主要记录Eureka的实现过程和高可用性的实现 Eureka是一个服务治理框架,它提供了Eureka Server和Eureka Client两个 ...

  9. MFC VC++ 根据文件名获取程序的Pid

    环境:PC Win7 VS VC++ .MFC 使用,输入文件名即可获取程序的pid,进而可以对程序进行操作,比如关闭Porcess等. 头文件: #include <TlHelp32.h> ...

  10. wc语法

    统计当前目录下的所有文件行数: wc -l * 当前目录以及子目录的所有文件行数: find  . * | xargs wc -l 可以把*改成所要匹配的文件,例如Java文件,*.java这样就只统 ...