D. Airplane Arrangements
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There is an airplane which has n rows from front to back. There will be m people boarding this airplane.

This airplane has an entrance at the very front and very back of the plane.

Each person has some assigned seat. It is possible for multiple people to have the same assigned seat. The people will then board the plane one by one starting with person 1. Each person can independently choose either the front entrance or back entrance to enter the plane.

When a person walks into the plane, they will walk directly to their assigned seat. Then, while the seat they’re looking at is occupied, they will keep moving one space in the same direction. A passenger will get angry if they reach the end of the row without finding their assigned seat.

Find the number of ways to assign tickets to the passengers and board the plane without anyone getting angry. Two ways are different if there exists a passenger who chose a different entrance in both ways, or the assigned seat is different. Print this count modulo 109 + 7.

Input

The first line of input will contain two integers n, m (1 ≤ m ≤ n ≤ 1 000 000), the number of seats, and the number of passengers, respectively.

Output

Print a single number, the number of ways, modulo 109 + 7.

Example
input
3 3
output
128
Note

Here, we will denote a passenger by which seat they were assigned, and which side they came from (either "F" or "B" for front or back, respectively).

For example, one valid way is 3B, 3B, 3B (i.e. all passengers were assigned seat 3 and came from the back entrance). Another valid way would be 2F, 1B, 3F.

One invalid way would be 2B, 2B, 2B, since the third passenger would get to the front without finding a seat.

一群人要登机,飞机有前后两个门,可以任意选择一门登机。n个座位m排问有多少种登机方法

只考虑从1个门登机,那么总数就要乘上2^m,因为每个人都有2种选择,接下来考虑座位的问题,看样子好像是一个人有座位了就必须向下移,如果把这些人按照座位排队的话(只考虑先后),那么我就应该乘上(n-m+1),其实只要确定第一个人,每个人都有n+1种排队的选择

综上 (n+1)^(m-1)*(n-m+1)*2^m

#include<stdio.h>
const int mod=1e9+;
int po(int x,int k)
{
int sum=;
while(k)
{
if(k&)
{
sum=1LL*sum*x%mod;
}
x=1LL*x*x%mod;
k>>=;
}
return sum;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
printf("%d\n",1LL*po(n+,m-)*(n-m+)%mod*po (,m)%mod);
return ;
}

IndiaHacks 2nd Elimination 2017 (unofficial, unrated mirror, ICPC rules)的更多相关文章

  1. 2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)

    2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) easy: ACE ...

  2. CF_2018-2019 Russia Open High School Programming Contest (Unrated, Online Mirror, ICPC Rules, Teams Preferred)

    只做了两个就去上课去啦... A. Company Merging time limit per test 1 second memory limit per test 512 megabytes i ...

  3. 2018-2019 ICPC, NEERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred) Solution

    A. Alice the Fan Solved. 题意: 两个人打网球,要求teamA 的得分与其他队伍拉开尽量大 输出合法的方案 思路: $dp[i][j][k][l] 表示 A 赢i局,其他队伍赢 ...

  4. 2018-2019 Russia Open High School Programming Contest (Unrated, Online Mirror, ICPC Rules, Teams Preferred)

    前言 有一场下午的cf,很滋磁啊,然后又和dalao(见右面链接)组队打了,dalao直接带飞我啊. 这是一篇题解,也是一篇总结,当然,让我把所有的题目都写个题解是不可能的了. 按照开题顺序讲吧. 在 ...

  5. 2019-2020 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred)

    这是一场三人组队赛来的,单人带电子模板不限时单挑试一下.按照难度排序. B - Balls of Buma 题意:玩祖玛,射入任意颜色的球一个,当某段长度变长了且长度变长后>=3则这段就会消除, ...

  6. 2021-2022 ICPC, NERC, Northern Eurasia Onsite (Unrated, Online Mirror, ICPC Rules, Teams Preferred) J. Job Lookup

    题意 n个节点,n<=200,你需要构造这n个几点成为一棵树,并且这棵树的中序遍历为1-n; 你构造树的节点之间的最短路构成一个n×n的最短距离矩阵d: 同时给你n×n的权重矩阵c:最最小的Σd ...

  7. 2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)【A题 类型好题】

    A. Berstagram Polycarp recently signed up to a new social network Berstagram. He immediately publish ...

  8. 2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules) D. Firecrackers (贪心,二分)

    题意:有个长度为\(n\)的监狱,犯人在位置\(a\),cop在位置\(b\),你每次可以向左或者向右移动一个单位,或者选择不动并在原地放一个爆竹\(i\),爆竹\(i\)在\(s[i]\)秒后爆炸, ...

  9. 2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules) C. Berpizza (STL)

    题意:酒吧里有两个服务员,每个人每次都只能服务一名客人,服务员2按照客人进酒吧的顺序服务,服务员3按照客人的钱来服务,询问\(q\),\(1\)表示有客人进入酒吧,带着\(m\)块钱,\(2\)表示询 ...

随机推荐

  1. GIT本地pull远程失败,本地tag与远程仓库不匹配问题

    2019-05-15 问题现象: 1.GIT本地目录无法pull下远程仓库已新增的内容,一直提示Already up to date  2.git log 命令显示没有远端的tag版本 $git lo ...

  2. 基于Myeclipse的三大框架(SSH)整合

    文中主要基于Myeclipse进行配置,配置流程为:Hibernate --> Spring --> 整合 --> struts2 -->整合.注意:在此文中,主要讲述基于注解 ...

  3. css水平垂直居中的几个方法和技巧/居中之美

    水平居中设置-行内元素     我们在实际工作中常会遇到需要设置水平居中场景,今天我们就来看看怎么设置水平居中的. 如果被设置元素为文本.图片等行内元素时,水平居中是通过给父元素设置 text-ali ...

  4. LR中订单流程脚本2

    Action(){ //1.设置服务器的IP地址 //lr_save_string("192.168.1.12:8080", "ip"); lr_save_st ...

  5. 总结SQL Server窗口函数的简单使用

    总结SQL Server窗口函数的简单使用 前言:我一直十分喜欢使用SQL Server2005/2008的窗口函数,排名函数ROW_NUMBER()尤甚.今天晚上我在查看SQL Server开发的相 ...

  6. DRM 简介

    首先,我们对和DRM 相关的一些概念进行介绍. Buffer: 对于RAC 数据库,当一个数据块被读入到buffer cache后,我们就称其为buffer , cache fusion 会将这个bu ...

  7. FaceBook pop 动画开源框架使用教程说明

    https://github.com/facebook/pop Pop is an extensible animation engine for iOS and OS X. In addition ...

  8. eclipse中Lombok注解无效

    问题现象:eclipse中使用lombok的@Date,引用get方法时,报错. 解决方案: 在lombok官网(https://www.projectlombok.org/download)下载,或 ...

  9. StringMVCWeb接受前台值的几种方式

    这些决定与request   header   的Content-Type属性 1.通过@RequestParam @RequestParam Map<String, Object> pa ...

  10. js的正则表达式总结

    1.8-20位数字 or  字母 or 特殊字符 var reg = /^[0-9a-zA-Z!@#$%^&*()_+-/.]{8,20}$/; 2.8-20位 数字+字母+特殊字符 //正则 ...