考虑设
g
(
x
)
g(x)
g(x)为
a
n
s
ans
ans的生成函数
那么有
g
(
x
)
=
f
(
x
)
g
(
x
)
+
1
g(x)=f(x)g(x)+1
g(x)=f(x)g(x)+1
g
(
x
)
=
1
1
−
f
(
x
)
g(x)=\frac{1}{1-f(x)}
g(x)=1−f(x)1
由于
f
(
x
)
=
f
(
x
)
x
+
f
(
x
)
x
2
+
x
f(x)=f(x)x+f(x)x^2+x
f(x)=f(x)x+f(x)x2+x
所以
f
(
x
)
=
x
1
−
x
−
x
2
f(x)=\frac{x}{1-x-x^2}
f(x)=1−x−x2x
g
(
x
)
=
1
+
x
1
−
2
x
−
x
2
g(x)=1+\frac{x}{1-2x-x^2}
g(x)=1+1−2x−x2x
那么有
g
(
x
)
=
2
x
g
(
x
)
+
x
2
g
(
x
)
+
x
g(x)=2xg(x)+x^2g(x)+x
g(x)=2xg(x)+x2g(x)+x
于是
a
n
s
[
i
]
=
2
a
n
s
[
i
−
1
]
+
a
n
s
[
i
−
2
]
ans[i]=2ans[i-1]+ans[i-2]
ans[i]=2ans[i−1]+ans[i−2]
#include<bits/stdc++.h>
using namespace std;
const int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ob==ib)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ob==ib)?EOF:*ib++;
}
#define gc getchar
inline int read(){
char ch=gc();
int res=0,f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
#define ll long long
#define re register
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define cs const
#define bg begin
template<class tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<class tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int mod=1e9+7;
inline int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
inline void Add(int &a,int b){(a+=b)>=mod?a-=mod:0;}
inline int dec(int a,int b){return (a-=b)<0?a+mod:a;}
inline void Dec(int &a,int b){(a-=b)<0?a+=mod:0;}
inline int mul(int a,int b){return 1ll*a*b%mod;}
inline void Mul(int &a,int b){a=1ll*a*b%mod;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
inline int Inv(int x){return ksm(x,mod-2);}
int f[1000005],n;
int main(){
n=read();
f[1]=1;
for(int i=2;i<=n;i++)f[i]=add(add(f[i-1],f[i-1]),f[i-2]);
cout<<f[n];
}