题目描述

You have a set $ S $ of $ n $ distinct integers between $ 1 $ and $ m $ .

Each second you do the following steps:

  1. Pick an element $ x $ in $ S $ uniformly at random.
  2. Remove $ x $ from $ S $ .
  3. If $ x+1 \leq m $ and $ x+1 $ is not in $ S $ , add $ x+1 $ to $ S $ .

What is the expected number of seconds until $ S $ is empty?

Output the answer modulo $ 1,000,000,007 $ .

Formally, let $ P = 1,000,000,007 $ . It can be shown that the answer can be expressed as an irreducible fraction $ \frac{a}{b} $ , where $ a $ and $ b $ are integers and $ b \not \equiv 0 \pmod{P} $ . Output the integer equal to $ a \cdot b^{-1} \bmod P $ . In other words, output an integer $ z $ such that $ 0 \le z < P $ and $ z \cdot b \equiv a \pmod{P} $ .

输入格式

$ 1 \leq n \leq m \leq 500,1 \leq S_1 < S_2 < \ldots < S_n \leq m $

见到 \(m\le 500\) 还愣了一下,没想到放了 \(m^3\) 过。

根据期望的线性性,考虑对某一个数消失的期望分开计算。

模拟一下发现,某一个数 \(a_i\) 不再加回集合的期望是只和 \(a_{i+1}\) 相关。尝试用一个 \(dp\) 去求出这个期望。

定义 \(dp_{i,j}\) 为现在 \(i\) 在走,下一个比他大的数是 \(j\) ,\(i\) 的期望步数。

\(dp_{i,m+1}=m+1-i,dp_{i,j}=(dp_{i+1,j}+dp_{i,j+1}+1)\times \frac 12\)

// LUOGU_RID: 122804271
#include<bits/stdc++.h>
using namespace std;
const int N=505,P=1e9+7,iv2=P+1>>1;
int dp[N][N],n,m,ans,s[N];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",s+i);
for(int i=m;i;i--)
{
for(int j=m+1;j>i;j--)
{
if(j<=m)
(dp[i][j]+=iv2*1LL*(dp[i+1][j]+dp[i][j+1]+1)%P)%=P;
else
dp[i][j]=dp[i+1][j]+1;
}
}
s[n+1]=m+1;
for(int i=1;i<=n;i++)
(ans+=dp[s[i]][s[i+1]])%=P;
printf("%d",ans);
}

[CF1854C] Expected Destruction的更多相关文章

  1. python中IndentationError: expected an indented block错误的解决方法

    IndentationError: expected an indented block 翻译为IndentationError:预期的缩进块 解决方法:有冒号的下一行要缩进,该缩进就缩进

  2. iOS10之Expected App Behaviors

    昨天上架到appStore的时候碰到个问题,构建好后上传到itunesconnect的的包都用不了, 显示错误为:此构建版本无效. 或者英文显示为:ITC.apps.preReleaseBuild.e ...

  3. hadoop程序问题:java.lang.IllegalArgumentException: Wrong FS: hdfs:/ expected file:///

    Java代码如下: FileSystem fs = FileSystem.get(conf); in = fs.open(new Path("hdfs://192.168.130.54:19 ...

  4. xcode6 使用MJRefresh,Too many arguments to function call, expected 0, have *

    转载自:  http://blog.csdn.net/wsjshx/article/details/40743291 将XCode升级到6后,报Too many arguments to functi ...

  5. Hive启动报错: Found class jline.Terminal, but interface was expected

    报错: [ERROR] Terminal initialization failed; falling back to unsupported java.lang.IncompatibleClassC ...

  6. 解决:error: Cannot fetch repo (TypeError: expected string or buffer)

    同步源码,问题重现: Fetching project platform/external/libopus Fetching project repo error: Cannot fetch repo ...

  7. C和指针 第十二章 结构体 整体赋值 error: expected expression

    定义结构体后整体赋值时发生错误 typedef struct NODE { struct NODE *fwd; struct NODE *bwd; int value; } Node; //声明变量 ...

  8. expected an indented block

    expected an indented block 在初步使用Python的时候遇到了" expected an indented block"报错信息,查询相关的博客得知是因为 ...

  9. JUnit4:Test注解的两个属性:expected和timeout

    JUnit4:Test文档中的解释: The Test annotation supports two optional parameters. The first, expected, declar ...

  10. Unity: Invalid serialized file version xxx Expected version: 5.3.4f1. Actual version: 5.3.5f1.

    Unity发布安卓项目,如果直接使用Unity打包APK一切Ok,导出Google项目 使用Idea打包 一进去直接Crash. 报错: 1978-2010/? E/Unity﹕ Invalid se ...

随机推荐

  1. 2023-08-22:请用go语言编写。给定一个长度为N的正数数组,还有一个正数K, 返回有多少子序列的最大公约数为K。 结果可能很大,对1000000007取模。 1 <= N <= 10^5, 1

    2023-08-22:请用go语言编写.给定一个长度为N的正数数组,还有一个正数K, 返回有多少子序列的最大公约数为K. 结果可能很大,对1000000007取模. 1 <= N <= 1 ...

  2. vue 脚手架文件结构及加载过程浅谈

    1. 初始化脚手架 1.1  全局安装 @vue/cli  npm install -g @vue/cli 1.2 切换到创建项目的目录,执行 vue create projectname 1.3 选 ...

  3. 9k+ Star 简洁好用的开源 Linux 运维管理面板

    如果你的公司需要进行服务器运维管理,那么运维管理面板就是一个不可或缺的需求.因为并非每一位运维工程师都能在命令行下游刃有余,不需要借助辅助工具就能确保服务器安全.流畅运行.尤其是对于刚刚踏入运维领域的 ...

  4. 商品详情api接口的应用方向有哪些?

    ​ 商品详情API接口的应用方向非常广泛,可以应用于以下领域: 电子商务平台:商品详情API接口可以提供商品的基本信息,如名称.描述.价格.图片等,帮助电子商务平台展示和推荐商品.此外,还可以提供商品 ...

  5. Codeforces Round #576 (Div. 2)

    A - City Day 题意:给n,x,y和数组a[n],求最小的下标d,使得有a[d-x,d-x+1,--d-1,d+1,d-1,d+1,--d+y-1,d+y]都比a[d]小,若d-x<= ...

  6. 「note」原根照抄

    阶(multiplicative order) \(\textbf{Def.}\):\(\delta_m(a)\) 为最小的 \(n\) 使得 \(a^n\equiv 1\pmod m\),其中 \( ...

  7. Ds100p -「数据结构百题」51~60

    纪念 数据结构一百题50题了呢,该过半周年啦~~~~ LYC和WGY半年的努力让这个几乎玩笑一般的系列到了现在. 今后也请多多关照啦. 祝愿dp100p早日过半 51.CF1000F One Occu ...

  8. AT 下分记录

    7.30 AGC063 \(+30=1620\) B 做法假 WA 了三次,为啥总是吃了罚时才能发现问题啊 心态还是需要解决的问题.过完 B 啥都想不出来又自闭了

  9. 5.go语言函数提纲

    1 本篇前瞻 前端时间的繁忙,未曾更新go语言系列.由于函数非常重要,为此将本篇往前提一提,另外补充一些有关go新版本前面遗漏的部分. 需要恭喜你的事情是本篇学完,go语言中基础部分已经学完一半,这意 ...

  10. Hadoop集群模式安装笔记

    前言 Hadoop集群=HDFS集群+YARN集群 特点:两个集群逻辑上分离,通常物理上在一起:并且都是标准的主从架构集群 Hadoop安装 方式一源码编译安装 方式二官方编译安装包 () 环境 Ce ...