题解 | #放苹果#

放苹果

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

f(m,n)=f(m-n,n)+f(m,n-1)==>f(m-n,n)苹果数量大于盘子数量,f(m,n-1)苹果数量小于盘子数量

import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
            System.out.println(count(sc.nextInt(),sc.nextInt()));
        }
    }
    
    public static int count(int m,int n){
        if(m==0||m==1||n==1){
            return 1;
        }
        if(m<0||n<0){
            return 0;
        }
        return count(m-n,n)+count(m,n-1);
    }
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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