考虑加入第 \(n + 1\) 个位置,这样座位构成了一个环。每个位置被覆盖的概率相等,为 \(\frac{m}{n + 1}\),然后算出概率再乘方案数就行了。
code
// Problem: D. Airplane Arrangements
// Contest: Codeforces - IndiaHacks 2nd Elimination 2017 (unofficial, unrated mirror, ICPC rules)
// URL: https://codeforces.com/problemset/problem/838/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;
const ll mod = 1000000007;
inline ll qpow(ll b, ll p) {
ll res = 1;
while (p) {
if (p & 1) {
res = res * b % mod;
}
b = b * b % mod;
p >>= 1;
}
return res;
}
ll n, m;
void solve() {
scanf("%lld%lld", &n, &m);
printf("%lld\n", (n + 1 - m) * qpow(n + 1, mod - 2) % mod * qpow(2 * (n + 1), m) % mod);
}
int main() {
int T = 1;
// scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}