这是个水题,但是有坑点。
我们可以这样考虑,我们从n个位置种选2个作为逆序对的两位置,一前一后也不用x2,然后对于剩下的n-2个位置,我们可以随便选,因为题目给了所有01串。所以C(n,2)* 就是答案。
坑点是要特判n=1的情况,然后对于组合数,如果你用除法的话,一定要变成逆元,不然会WA
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n;
const ll mo=1e9+7;
ll qp(ll a,ll b)
{
ll res=1;
while(b)
{
if(b&1)res=res*a%mo;
a=a*a%mo;
b>>=1;
}return res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
if(n<2) return cout<<0,0;
ll tt=qp(2,n-2)%mo;
ll t=(n%mo)* ((n-1)%mo)%mo*(qp(2,mo-2)%mo) %mo;
cout<<tt*t%mo;
return 0;
}


京公网安备 11010502036488号