题目
  • 现在一圈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. Windows IIS服务挂载NAS共享文件存储

    本文介绍如何结合阿里云NAS的SMB协议支持和ECS Windows虚拟机,使用Windows内置的互联网信息服务(IIS)来提供Web和FTP服务. 阿里云文件存储服务NAS主要面向阿里云ECS 实 ...

  2. Java中的值传递与引用传递

    1.基本类型和引用类型在内存中的保存 Java中数据类型分为两大类,基本类型和对象类型.相应的,变量也有两种类型:基本类型和引用类型. 基本类型的变量保存原始值,即它代表的值就是数值本身: 而引用类型 ...

  3. [Linux]Redhat7配置本地镜像源

    一.Redhat7源 上一个文章介绍了如何配置的Redhat7的YUM网络源:[Linux]Redhat7配置CentOS7 YUM源 .如果在无法联网的情况下,可以使用镜像文件作为源安装需要的包. ...

  4. C语言:统计数字空格其他字符程序

    #include <stdio.h> int main(){ char t; int num=0; int spac=0; int other=0; int sum=0; printf(& ...

  5. RSA加密及加签

    1.对方要求我们的私钥是pkcs8格式,但是实际的公钥没有用pkcs8转换之后的私钥完成,所以是可以不是pkcs8的格式的.我们加签跟格式没有关系. 2.数据格式很重要,to_mpint而非crypt ...

  6. 无法对含有多个.java(或.class)文档的程序进行编译(或解释)

    通常初学者会出现这样的问题:无法对含有多个.java(或.class)文档的程序进行编译(或解释). root@yogile-VirtualBox:/alive/string# javac work/ ...

  7. (转)junit简介

    什么是单元测试? 所谓单元测试是测试应用程序的功能是否能够按需要正常运行,并且确保是在开发人员的水平上,单元测试生成图片.单元测试是一个对单一实体(类或方法)的测试.单元测试是每个软件公司提高产品质量 ...

  8. libnids-1.24 使用源码问题

    从网上下载libnids-1.24源码包,解压后./configure安装. 会出现提示 checking for GLIB... configure: error: Package requirem ...

  9. Python全栈之路----函数进阶----列表生成式

    列表生成式 现在有个需求,看列表[0,1,2,3,4,5,6,7,8,9],要求你把列表里每个值都加1,你怎么实现?你可能会想到两种方法. 二逼青年版 >>> a = [0,1,2, ...

  10. Visual Studio AI 离线模型训练(Windows10)

    一.序 环境搭建:[查看] samples-for-ai项目下载:[下载],两个版本,一个2018年6月15日前,一个2018年6月15日-16日版本(当前最新版本). 在环境搭建过程中,通过git ...