题目描述

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

    目录 简介 运行 制作vm文件系统 制作vm基础文件系统文件 创建contianerdClient 创建cniInstance 拉取基础镜像 创建基础文件系统文件 制作vm内核文件 Create vm ...

  2. .NET开源最全的第三方登录整合库 - CollectiveOAuth

    前言 我相信很多同学都对接过各种各样的第三方平台的登录授权获取用户信息(如:微信登录.支付宝登录.GitHub登录等等).今天给大家推荐一个.NET开源最全的第三方登录整合库:CollectiveOA ...

  3. springboot集成seata1.5.2+nacos2.1.1

    一.前言 Seata出现前,大部分公司使用的都是TCC或者MQ(RocketMq)等来解决分布式事务的问题,TCC代码编写复杂,每个业务均需要实现三个入口,侵入性强,RocketMQ保证的是最终一致性 ...

  4. ipmitool配置机器的BMC

    一.设置IP地址 1.确定操作对象 #ipmitool mc info 输出中"Device Revision"是命令的操作对象 2.设置BMC IP # ipmitool -I ...

  5. ATtiny88初体验(七):TWI

    ATtiny88初体验(七):TWI TWI模块介绍 ATtiny88的TWI模块兼容Phillips I2C以及SMBus,支持主从模式,支持7bit地址,最大允许128个不同的从机地址.在多主机模 ...

  6. Mysql基础篇-查询、函数、多表、事务

    1. 基础篇 1.1 mysql用户和权限管理 查询用户 USER mysql; SELECT * FROM user; 创建用户 CREATE USER '用户名'@'主机名' IDENTIFIED ...

  7. Avalonia开发(一)环境搭建

    一.介绍 开源 GitHub:https://github.com/AvaloniaUI/Avalonia/ 多平台支持,包括Windows.mac OS.Linux.iOS.Android.Sams ...

  8. 【RocketMQ】消息的消费总结

    消费者从Broker拉取到消息之后,会将消息提交到线程池中进行消费,RocketMQ消息消费是批量进行的,如果一批消息的个数小于预先设置的批量消费大小,直接构建消费请求ConsumeRequest将消 ...

  9. #POWERBI_指标监控(第二部分,周期内下降天数及日期明细)

    在指标监控的第一部分文章中,我们已经讲了,如何用DAX去查询一段周期内连续下降或者上升指标. 需要复习的同学可以点击下方链接: https://www.cnblogs.com/simone331/p/ ...

  10. 【知识杂谈#1】Linux如何安装net-tools和sbin配置PATH

    1. Linux下载net-tools 在Linux上下载net-tools包的方法可能会因你所使用的Linux发行版而有所不同.在某些现代的Linux发行版中,net-tools已经被弃用,而推荐使 ...