题目描述

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. Pytest+Jenkins 学习笔记

    Pytest+Jenkins 学习笔记 在软件测试工作中,单元测试通常是由开发人员执行的.针对最小单元粒度的组件测试,在完成了单元粒度的测试任务之后,通常就需要交由专职的测试人员将这些单元级的组件放到 ...

  2. 【项目源码】基于Spring + Spring MVC + MyBatis的图书馆管理系统

    基于Spring + Spring MVC + MyBatis的图书馆管理系统.主要功能包括:图书查询.图书管理.图书编辑.读者管理.图书的借阅与归还以及借还日志记录等​,非常适合学习研究. 运行配置 ...

  3. WPF动画入门教程

    Windows Presentation Foundation (WPF)是一种用于创建Windows客户端应用程序的UI框架.它让我们能够创建丰富的图形界面,包括各种各样的动画效果.接下来,我们将介 ...

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

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

  5. 「atcoder - ABC215G」Colorful Candies 2

    link. 称题目中的 \(c_i\) 为 \(a_i\),令 \(c_i\) 为第 \(i\) 种颜色的出现次数,令 \(C\) 为颜色总数.固定 \(k\),令 \(t_i=1\),如果颜色 \( ...

  6. SSM-Mybatis笔记

    目录 Mybatis-9.28 1.简介 1.1.什么是Mybatis 1.2.持久化 1.3.持久层 1.4 为什么需要Mybatis? 2.第一个Mybatis程序 2.1.搭建环境 2.2.创建 ...

  7. oracle 问题:ORA-28040:没有匹配的验证协议

    Oracle11g客户端连接Oracle12C服务器端,需配置项 前置条件:已安装Oracle11g客户端,配置好环境变量,用PL/SQL Developer登录数据库 出现问题:登录数据库时,提示& ...

  8. 其它——各主流Linux系统解决pip安装mysqlclient报错

    文章目录 一 CentOS(红帽) 二 Ubuntu 三 Windows 一 CentOS(红帽) #CentOS有Python.Mysql的开发工具包,安装后使用pip安装mysqlclient即可 ...

  9. ERROR: nginx-1.22.1 installation failed.

    libraries. You can either do not enable the module or install the libraries.make: *** No rule to mak ...

  10. idea修改默认maven配置

    idea修改默认maven配置 方法一 (不推荐) 打开project.default.xml文件,在其中加入如下几行配置. 代码如下 保存修改之后新建一个maven项目查看效果 方法二 新增Proj ...