【CF838D】Airplane Arrangements【结论题】

传送门

solution

考虑我们在\(n+1\)这个位置上也放一个座位,然后将座位接成环,那么每个人一定都能找到座位,但一旦有人坐到第\(n+1\)个位置上就会导致这个人\(angry\)

因为是一个环,所以坐到每一个空位上的概率完全相同,那么不做到第\(n+1\)位值得概率就是:\(\frac{n+1-m}{n+1}\),再乘上方案数\((2n+2)^m\)就是答案了:

code

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,m;
inline int ksm(int a,int b){
	int ret=1;
	for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) ret=1ll*ret*a%mod;
	return ret;
}
int main(){
	scanf("%d%d",&n,&m);
	printf("%d\n",2ll*ksm(2*n+2,m-1)%mod*(n+1-m)%mod);
	return 0;
}
原文地址:https://www.cnblogs.com/tqxboomzero/p/14218520.html