Codeforces #838D: Airplane Arrangement 题解

一道神题
考虑把座位拉成一个环,这样就不存在没有位置的情况了
在第一个和最后一个之间加一个座位,这样只要这个座位被占就说明这个安排不合法
我们发现这个环是完全对称的,所以每个位置被占的概率是一样的
我们考虑所有的选法,现在有n+1个座位,有两种方向,所以有 (2(n+1))m ( 2 ( n + 1 ) ) m 种安排方式
我们考虑选中合法方案的概率,从n+1个椅子里面挑m个被占,其中不能有1和n之间的那一把,所以是 CmnCmn+1=n!m!(nm)!m!(nm+1)!(n+1)!=nm+1n+1 C n m C n + 1 m = n ! m ! ( n − m ) ! m ! ( n − m + 1 ) ! ( n + 1 ) ! = n − m + 1 n + 1
所以答案是 (2n+2)mnm+1n+1 ( 2 n + 2 ) m ∗ n − m + 1 n + 1

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <utility>
#include <cctype>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#define LL long long
#define LB long double
#define x first
#define y second
#define Pair pair<int,int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const LL LINF=2e16;
const int INF=2e9;
const int magic=348;
const double eps=1e-10;
const double pi=3.14159265;

inline int getint()
{
    char ch;int res;bool f;
    while (!isdigit(ch=getchar()) && ch!='-') {}
    if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
    while (isdigit(ch=getchar())) res=res*10+ch-'0';
    return f?res:-res;
}

int m,n;

inline LL quick_pow(LL x,LL y)
{
    LL res=1;
    while (y)
    {
        if (y&1) res=(res*x)%MOD,y--;
        x=(x*x)%MOD;y>>=1;
    }
    return res;
}

int main ()
{
    n=getint();m=getint();
    printf("%lld\n",((quick_pow(2*n+2,m)*(n-m+1))%MOD*quick_pow(n+1,MOD-2))%MOD);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值