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