Description
Input
Sample Input
2
Output
Sample Output
问1-n,n个数的全排列中有多少个满足单峰序列的性质,并把答案mod 1e9+7
这题还是很简单的,一开始打了一个50分的做法,然后发现答案就是 2n−1 ,然后没有发现输入也会爆,于是就得了50分
我们容易发现峰一定是最大的那个数,我们把峰放到每一个位置上,然后在往峰的左边随便填一些数,每种填数的方法一定有且只有一种对应的合法方法,那么一共就有 2n−1 种做法(用快速幂,注意范围)
const md=1000000007;
var
i,j,k,l:longint;
ans,x,p,n:int64;
function quickmi(x,y:int64):int64;
var
i:int64;
s:int64;
begin
i:=1;
s:=x;
quickmi:=1;
while i<=y do
begin
if y and i<>0 then quickmi:=(quickmi*s) mod md;
i:=i*2;
s:=(s*s) mod md;
end;
exit(quickmi);
end;
begin
readln(n);
n:=n-1;
ans:=1;
x:=quickmi(2,n);
writeln(x);
end.