[jzoj 4742] 单峰 {快速幂}

版权声明:~~~感谢支持! https://blog.csdn.net/qq_39897867/article/details/88368264

题目

在这里插入图片描述在这里插入图片描述在这里插入图片描述


解题思路

可以发现,峰顶一定是 n,因此考虑 1 n 1 1 ∼ n − 1 分别放在 n n 的左边还是右边,得出相应的唯一答案。所以答案就是 2 n 1 2^{n−1}


代码

#include<cstdio>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;
const ll ymw=1e9+7; 
ll n; 
ll ksm(ll x,ll y){
	ll p=1; 
	for (;y;y>>=1,(x*=x)%=ymw) if (y&1) (p*=x)%=ymw; 
	return p; 
}
int main(){
	scanf("%lld",&n); 
	printf("%lld",ksm(2,n-1)); 
}

猜你喜欢

转载自blog.csdn.net/qq_39897867/article/details/88368264