题解 | 数楼梯

数楼梯

https://www.nowcoder.com/practice/c7e5f164fa5d471f8f83c90fe4ee3f05

/*
 注意每一步都要除998244353,而不是最后再除
*/



#include <iostream>
#include<vector>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin>>n;
    vector<long long>dp(1e5 + 10);
    dp[1] = 1;
    dp[2] = 2;
    if(n < 3){
        cout<<n<<'\n';
        return 0;
    }
    for(int i = 3 ; i <= n;i++){
        dp[i] = (dp[i - 1] + dp[i - 2]) %  998244353; 
    }
    cout<<dp[n] <<'\n';
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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