传送门:https://codeforces.com/contest/1391/problem/C
排列如果是单峰就不能构成环,找最大值的位置出现的地方,然后再找一下左右出现的组合
题目:
ac代码:
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long int LL ;
LL mod = 1e9 + 7 ;
LL kuai(LL A , LL B , LL C)
{
LL res = 1 % C;
for(;B; B>>= 1)
{
if(B & 1)res = res * A % C;
A = A * A % C;
}
return res;
}
int main()
{
LL n ;
LL ans = 1;
cin >> n ;
for(int i = 1; i <= n ; i ++)
{
ans = ans * i % mod;
}
LL temp = kuai(2,n - 1, 1e9 + 7);
cout << (ans - temp + mod)%mod<<endl;
}
// 135712853
// 406973376