题解 | #放苹果#

放苹果

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
                 Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            int m = sc.nextInt();
            int n = sc.nextInt();
            System.out.println(sum(m,n));
        }
    }

        public static int sum(int m,int n){

            if(m<0 || n<0){
                return 0;
            }

        if (m==0 || n==1 || m==1){
            return 1;
        }

        //m>n  sum(m,n-1)  每次多一个空盘子
        //m<n  sum(m-n,n)  将多余的苹果放到n个盘子里面
        return sum(m,n-1)+sum(m-n,n);
    }
    
}

全部评论

相关推荐

2025-12-18 19:36
已编辑
门头沟学院 Java
程序员牛肉:可以的,简历没毛病了。 虽然还是偏向同质化,不过学历不错。后续我觉得重心放到刷实习+摆脱同质化问题上
实习简历求拷打
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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