正题
题目大意
求1∼n1\sim n1∼n的全排列中有多少个满足单峰
解题思路
现在考虑一个单峰,我们加入一个更小的数,要么插在最左边,要么插在最右边,所以得出答案结论2n−12^{n-1}2n−1
codecodecode
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const ll XJQ=1e9+7;
ll n;
ll power(ll x,ll b)
{ll ans=1;while(b){if(b&1) ans=ans*x%XJQ;x=x*x%XJQ;b>>=1;}return ans;
}
int main()
{scanf("%lld",&n);printf("%lld",power(2,n-1));
}