题目描述: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. hdu 4975 A simple Gaussian elimination problem 最大流+找环

    原题链接 http://acm.hdu.edu.cn/showproblem.php?pid=4975 这是一道很裸的最大流,将每个点(i,j)看作是从Ri向Cj的一条容量为9的边,从源点除法连接每个 ...

  2. 服务器Out of Memory

    之前有次把图片存储在数据库,结果读取时候报错了:Out of Memory.. 图片本来不应该存储在数据库中的,消耗内存太大,既然已经这样,那就先解决问题,不改存储方式. 如果一个应用程序为了提高性能 ...

  3. 【面试 hibernate】【第二篇】hibernate相关问题

    1.hibernate工作原理[说一下你怎么理解的hibernate] hibernate是一个ORM对象关系映射的持久层框架,是对JDBC的轻量级封装. [可以不记,hibernate核心接口] 1 ...

  4. 生成和解析txt文件

    package txt; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; imp ...

  5. React 组件开发注意事项

    0.state的设定原则,如果render里用不到,则就不应该是一个state. 1.数组遍历时,用每一条数据的唯一标识作为key,尽量不要使用遍历的索引值作为key,如果它们从不重新排序,它们工作也 ...

  6. Andriod 从源码的角度详解View,ViewGroup的Touch事件的分发机制

    转自:xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/21696315) 今天这篇文章主要分析的是Android的事件分发机制, ...

  7. Android手机输入法按键监听-dispatchKeyEvent

    近期在项目开发中遇到一个关于手机输入键盘的坑.特来记录下. 应用场景: 项目中有一个界面是用viewpaper加三个fragment写的,当中viewpaper被我屏蔽了左右滑动,上面有三个点击按钮, ...

  8. Computer form factor

    http://en.wikipedia.org/wiki/Motherboard_form_factor Computer form factor From Wikipedia, the free e ...

  9. 使用JXL对EXCLE的导入导出

    import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Da ...

  10. java中类加载顺序(深入Java)

    未涉及虚拟机 0.<init>与<clinit>的区别 1.类的加载过程 2.类的使用方式 3.类的加载来源 4.重载之泛型参数不同可以吗 5.参考 引子 记得上次中秋一哥们写 ...