题解 | #Where in 和Not in#

放苹果

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

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    String str = null;
   
    while((str = in.readLine()) != null){
        String[] s = str.split(" ");
        int m = Integer.parseInt(s[0]);
        int n = Integer.parseInt(s[1]);
        System.out.println(putApple(m,n));
    }
    
}
public static int putApple(int m,int n){
    if(m == 0) return 1;
    if(n == 0) return 0;
    if(m < n) return putApple(m,m);
    else return putApple(m - n,n) + putApple(m,n-1);
}

}

我居南半坡 文章被收录于专栏

多刷题,积蓄力量,欢迎讨论

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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