【NOIP2016提高组模拟】单峰

来源:互联网 发布:科比生涯数据场均 编辑:程序博客网 时间:2024/05/20 09:27

Description

这里写图片描述

Data Constraint

这里写图片描述

Solution

首先要有一个思路,就是作为峰的数值只能是N。有了这点就很好思考了,假设当前N的答案为ans,对于N+1,为了使加入N+1后的序列符合要求,那么N+1只能添加在N的左或右,那就意味着N+1的答案是N的答案的2倍,所以答案为2n1。观察到数据范围,显然用快速幂。

Code

const mo=1000000007;var    n,i,mi,ans,tot:int64;    s:array[1..100] of longint;begin    readln(n);    dec(n);    s[1]:=2; tot:=2; i:=1; mi:=1;    while mi*2<=n do    begin        inc(i);        mi:=mi*2;        tot:=(tot*tot)mod mo;        s[i]:=tot;    end;    ans:=tot; n:=n-mi;    while n>0 do    begin        dec(i);        mi:=mi div 2;        if n>=mi then        begin            n:=n-mi;            ans:=(ans*s[i])mod mo;        end;    end;    writeln(ans);end.
0 0