题目描述: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. Django实现的博客系统中使用富文本编辑器ckeditor

    操作系统为OS X 10.9.2,Django为1.6.5. 1.下载和安装 1.1 安装 ckeditor 下载地址 https://github.com/shaunsephton/django-c ...

  2. android 获得SDCard信息

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...

  3. 【JSON注解】注解@JsonIgnoreProperties和@JsonIgnore的另一个使用情况

    之前关于这两个注解,是用在JSON循环引用的情况上,那么现在关于这两个注解,还可以使用在另外一种情况上 即: 一般标记在属性或者方法上,返回的json数据即不包含该属性 关于这种情况在什么时候会遇到呢 ...

  4. 有方向的运动js

    <!doctype html> <html lang="en"> <head>     <meta charset="UTF-8 ...

  5. Leetcode第1题至第10题 思路分析及C++实现

    笔者按照目录刷题,对于每一道题,力争使用效率最高(时间复杂度最低)的算法,并全部通过C++代码实现AC.(文中计算的复杂度都是最坏情况复杂度) 因为考虑到大部分读者已经在Leetcode浏览过题目了, ...

  6. 创建pycharm项目时项目解释器的选择

    创建pycharm项目时项目解释器的选择 Location下面有一个Project Interpreter: Python3.6,打开之后有两个选项, 如果选择了第一个,项目创建之后,在cmd中pip ...

  7. sort-list——链表、快慢指针找中间、归并排序

    Sort a linked list in O(n log n) time using constant space complexity. 链表,快慢指针找中点,归并排序. 注意判断条件fast-& ...

  8. MYSQL时间戳的处理

    date为需要处理的参数(该参数是Unix 时间戳),可以是字段名,也可以直接是Unix 时间戳字符串 后面的 '%Y%m%d' 主要是将返回值格式化 例如: mysql>SELECT FROM ...

  9. linux系列之-—03 压缩和解压缩命令

    tar命令 解包:tar zxvf FileName.tar 打包:tar czvf FileName.tar DirName gz命令 解压1:gunzip FileName.gz 解压2:gzip ...

  10. CA与数字证书的自结

    1.CA CA(Certificate Authority)是数字证书认证中心的简称,是指发放数字证书.管理数字证书.废除数字证书的权威机构. 2.数字证书 如果向CA申请数字证书的单位为A.则他申请 ...