题解 | 数楼梯

数楼梯

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int count = in.nextInt();
        if(count==0){
            System.out.println(0);
            return;
        }else if(count==1){
            System.out.println(1);
            return;
        }
        long[] dp = new long[count];
        dp[0] = 1;
        dp[1] = 2;
        for(int i = 2; i < count; i++){
            dp[i] = (dp[i-1] + dp[i-2])%998244353;
        }
        long res = dp[count-1];
        System.out.println(res);
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
03-30 21:35
爱蜜莉雅碳劝退测开:裁员裁大动脉了
点赞 评论 收藏
分享
04-08 16:35
门头沟学院 Java
站队站对牛:实在是恶心的公司
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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