题目描述

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. 0×03 Vulnhub 靶机渗透总结之 KIOPTRIX: LEVEL 1.2 (#3) SQL注入+sudo提权

    0×03 Vulnhub 靶机渗透总结之 KIOPTRIX: LEVEL 1.2 (#3) 系列专栏:Vulnhub靶机渗透系列 欢迎大佬:点赞️收藏关注 首发时间: 2023年8月22日 如有错误 ...

  2. 深入了解API接口技术及其应用

    尊敬的读者们,大家好!在互联网时代,API(Application Programming Interface)接口已经成为开发者们连接各种应用.获取数据的重要工具.今天,我们将深入探讨API接口技术 ...

  3. SpringBoot整合ueditor编辑器

    1.到ueditor编辑器官网下载jsp版(目前官网地址改为了GitHub)https://ueditor.baidu.com/website/download.html2.下载解压后复制到当前项目3 ...

  4. MySQL数据库触发器讲解 [创建/删除/查询/select into]

    刚学习实例完mysql触发器, 前来分享学习经验.    菜鸟装逼,  老鸟勿喷 先来认识一下有关触发器的一些关键词.  在使用触发器时, 这些关键词将被用到, 请记下它们的模样和用途(意思) cre ...

  5. Vue 搭配 Spring MVC 创建一个 web 项目

    Vue 搭配 Spring MVC 创建一个 web 项目 想要写一个登录的web应用程序.页面使用Vue,后端使用Spring MVC,最终打成war包,放在tomcat下启动. 1.创建Sprin ...

  6. 聊聊wireshark的进阶使用功能

    1. 前言 emmm,说起网络知识学习肯定离不来wireshark工具,这个工具能够帮助我们快速地定位网络问题以及帮助正在学习网络协议这块的知识的同学验证理论与实际的一大利器,平时更多的只是停留在初步 ...

  7. Redis系列23:性能优化指南

    Redis系列1:深刻理解高性能Redis的本质 Redis系列2:数据持久化提高可用性 Redis系列3:高可用之主从架构 Redis系列4:高可用之Sentinel(哨兵模式) Redis系列5: ...

  8. 【题解】《PTA-Python程序设计》题目集分享

    第1章-1 从键盘输入两个数,求它们的和并输出 (30 分) 本题目要求读入2个整数A和B,然后输出它们的和. 输入格式: 在一行中给出一个被加数在另一行中给出一个加数 输出格式: 在一行中输出和值. ...

  9. [NSSCTF 2022 Spring Recruit]ezgame

    打开题目,发现是一个网页小游戏,就开始F12 提示到,需要分数超过65,才会得到flag 但不可能用手点吧(不怕麻烦还是可以) flag肯定是藏在了某个地方,仔细找找 发现有一个css,js文件,依次 ...

  10. 什么???CSS也能原子化!

    1.什么是原子化 CSS? Atomic CSS is the approach to CSS architecture that favors small, single-purpose class ...