题目
  • 现在一圈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的下载与项目的创建

    一.Django的下载安装 Django官网下载页面 二.DOS窗口下的django项目从创建和启动 1. DOS窗口下载Django pip3 install django==1.11.9 2.DO ...

  2. Python *Mix_w8

    文件操作的函数 文件可迭代 open(文件名(路径), mode="?", encoding="字符集") f = open("../Python/是 ...

  3. ubuntu14.04安装 Apache2 并配置https

    一.安装 Apache2 sudo apt-get update sudo apt-get install apache2 安装完apache2,默认根目录在/var/www/html 下,点击其下的 ...

  4. scrapy中crawlspide中callback和follow函数的作用及使用方法

    Rule(LinkExtractor(allow=r'i/tems'),callback='parse_item',follow=True)  当前代码的含义就是将当前页面及按照allow=r'i/t ...

  5. python:3种爬虫的优缺点

                                                                 性能对比            爬取方法            性    能 ...

  6. sql中的内联和外联(简单用法)

    有两张表:user和department User表: CREATE TABLE `user` (    `id` int(11) NOT NULL AUTO_INCREMENT,    `name` ...

  7. keras中VGG19预训练模型的使用

    keras提供了VGG19在ImageNet上的预训练权重模型文件,其他可用的模型还有VGG16.Xception.ResNet50.InceptionV3 4个. VGG19在keras中的定义: ...

  8. 常见模块(三) pickle模块和json模块

    (一)json和pickle的区别 1.json是不同编程语言实现数据交换的工具,他是用来把python中的数据对象转换成字符串或者写入文件中的,再由其他语言通过json加载进来. 2.pickle是 ...

  9. RabbitMQ安装记录(windows10)

    RabbitMQ安装记录(windows10)   一.安装包准备 otp_win64_R16B03.exe(这里使用该版本,不支持ssl) otp_win64_19.0.exe(如果要开启ssl,请 ...

  10. 用virtualenv建立独立虚拟环境 批量导入模块信息

    pip3 install virtualenv mkdir env/env1 source bin/activate pip3 freeze >requirements.txt or pipre ...