题解 | 小红蹦跳蹦跳

小红蹦跳蹦跳

https://www.nowcoder.com/practice/6f4a93135cc54f4ba840947691efa053

//(a+b)modP=[(amodP)+(bmodP)]modP
//(a×b)modP=[(amodP)×(bmodP)]modP
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int P=1e9+7;
void solve() {
    int n;cin>>n;
    vector<int>dpl(n+1,0),dpr(n+1,0);
    dpl[1]=1;dpr[1]=0;dpl[2]=0;dpr[2]=1;
    for(int i=3;i<=n;i++){
        dpl[i]=(dpr[i-1]+dpl[i-2])%P;
        dpr[i]=(dpr[i-2]+dpl[i-2])%P;
    }
    int ans=(dpl[n]+dpr[n])%P;
    cout<<ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

这个简历还有救吗,考研失利了,完蛋蛋了
helloWord大...:每次看见你们9爷隔着嚷嚷找不到工作,我真的分不清是串还是装
点赞 评论 收藏
分享
喵_coding:年底缺人是短视频营造出来的 而且一般说的也很宽泛 不是特指后端
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务