题目描述:https://www.luogu.org/problemnew/show/CF838D(有翻译)

(为什么博客园把我刚写的给吞了……orz)

这题当初看的十分懵逼,不过听了肖大佬的做法还是很清楚的。

因为乘客们可以从双向进入,然后乘客只会看给自己安排的座位和后面的空座位,所以我们不如直接新建一个虚拟座位,把这个序列变成一个环。乘客在找不到真实座位中找不到座位了,自然就会坐到虚拟位置上。因此,如果一个方案中虚拟位置被坐了说明不合法,否则就合法。

虚拟位置与其他位置一样是一个普通的座位,对于m个人来说,其没有被占据的概率为(n+1-m) / (n+1)。而所有的安排数是(2*(n+1)) ^ m,他们的乘积整理出来就是结果,即2^m * (n+1) ^ (m-1) * (n+1-m)

代码很短。(数学题大都难想……不过代码却可能很短)

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#define rep(i,a,n) for(int i = a;i <= n;i++)
#define per(i,n,a) for(int i = n;i >= a;i--)
#define enter putchar('\n')
using namespace std;
typedef long long ll;
const ll mod = 1e9+;
const int M = ;
ll read()
{
ll ans = ,op = ;
char ch = getchar();
while(ch < '' || ch > '')
{
if(ch == '-') op = -;
ch = getchar();
}
while(ch >= '' && ch <= '')
{
ans *= ;
ans += ch - '';
ch = getchar();
}
return ans * op;
} ll n,m;
ll qpow(ll a,ll b)
{
ll q = ;
while(b)
{
if(b&) q *= a,q %= mod;
a *= a,a %= mod;
b >>= ;
}
return q;
}
int main()
{
n = read(),m = read();
printf("%lld\n",qpow(,m) * qpow(n+,m-) % mod * (n+-m) % mod);
return ;
}

CF838D Airplane Arrangement的更多相关文章

  1. CF838D Airplane Arrangements

    传送门:https://www.luogu.org/problemnew/show/CF838D 这道题反正我自己想是毫无头绪,最后还是听了肖大佬的做法. 因为题中说乘客可以从前后门进来,所以我们可以 ...

  2. 洛谷 P6672 - [清华集训2016] 你的生命已如风中残烛(组合数学)

    洛谷题面传送门 题解里一堆密密麻麻的 Raney 引理--蒟蒻表示看不懂,因此决定写一篇题解提供一个像我这样的蒟蒻能理解的思路,或者说,理解方式. 首先我们考虑什么样的牌堆顺序符合条件.显然,在摸牌任 ...

  3. [leetcode-526-Beautiful Arrangement]

    Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is const ...

  4. zoj3777 Problem Arrangement

    The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem setter, Edward i ...

  5. ZOJ 3777-Problem Arrangement(状压DP)

    B - Problem Arrangement Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %l ...

  6. [LeetCode] Beautiful Arrangement II 优美排列之二

    Given two integers n and k, you need to construct a list which contains n different positive integer ...

  7. [LeetCode] Beautiful Arrangement 优美排列

    Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is const ...

  8. [Swift]LeetCode526. 优美的排列 | Beautiful Arrangement

    Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is const ...

  9. Intro to Airplane Physics in Unity 3D – 2017 and 2018

    Info:DescriptionHave you ever wanted to build your own Airplane Physics using the Rigidbody componen ...

随机推荐

  1. android调用 .net webService

    package com.rockcheck.mes; import android.os.AsyncTask; import android.support.v7.app.AppCompatActiv ...

  2. 扰动函数和拉链法模拟HashMap的存储结构

    HashMap是Map接口下面的子孙,它对外是K,V结构存储的,而内部也着自己的存储结构,它的get操作是O(1)的时间复杂度,可以说是非常快的找到目录,而添加时,也是O(1),所以在键值存储里,它成 ...

  3. NOIPSB评测机+SB题DAY2

    忍者钩爪 题目描述 小 Q 是一名酷爱钩爪的忍者, 最喜欢飞檐走壁的感觉, 有一天小 Q 发现一个练习使用钩 爪的好地方,决定在这里大显身手. 场景的天花板可以被描述为一个无穷长的数轴, 初始小 Q ...

  4. Springboot 工具类静态注入

    用springboot搭了一个项目,里面要用到一个DictUtils,因为要用到DictMapper,在百度找了一些方法,最后用下面的方法能成功获取到DictMapper @Component pub ...

  5. 算法笔记字符串处理问题H:编排字符串(2064)

    题目描述 请输入字符串,最多输入4 个字符串,要求后输入的字符串排在前面,例如 输入:EricZ 输出:1=EricZ 输入:David 输出:1=David 2=EricZ 输入:Peter 输出: ...

  6. Servlet(生命周期)

    <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" ...

  7. 使用crontab定时执行脚本时别忘了输出重定向>

    原文:https://blog.csdn.net/solmyr_biti/article/details/50683279 -------------------------------------- ...

  8. AWS向中国有限预览客户推出多级别AWS支持服务

     2014年9月26日 在AWS中国(北京)区域有限预览服务开展的过程中.很多客户都提出了对AWS支持服务(AWS Support)的需求. AWS客户在向云端部署系统,日常运营维护以及关键性项目实 ...

  9. ZT:CSS实现水平|垂直居中漫谈

    有篇博客园网友‘云轩奕鹤’的文章不错,转载在这里以供需要时查阅. http://www.cnblogs.com/jadeboy/p/5107471.html

  10. 小程序 - tabBar

    Tips:如果网页图片(文字)看不清,请按CTRL+鼠标滚轮 1.建议使用阿里图库 或者 easyicon 2.建议使用81*81且低于40KB的图片(建议jpg) 3.如需查看脑图结构,请点击:ta ...