• IndiaHacks 2nd Elimination 2017 (unofficial, unrated mirror, ICPC rules)


    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+7;
    int po(int x,int k)
    {
        int sum=1;
        while(k)
        {
            if(k&1)
            {
                sum=1LL*sum*x%mod;
            }
            x=1LL*x*x%mod;
            k>>=1;
        }
        return sum;
    }
    int main()
    {
        int n,m;
        scanf("%d%d",&n,&m);
        printf("%d
    ",1LL*po(n+1,m-1)*(n-m+1)%mod*po (2,m)%mod);
        return 0;
    }
  • 相关阅读:
    CrashSight异常崩溃管理解决方案
    网址
    错误“Permission is not allowed”
    python连接虚拟机
    python对json文件的编码问题
    python取二次编码地图数据进行遍历修改再二次编码
    python对省份json的二次编码和二次解码
    H5调起支付宝支付
    人生~~~~
    部署服务的5中方式
  • 原文地址:https://www.cnblogs.com/BobHuang/p/7305083.html
Copyright © 2020-2023  润新知