题解 | #放苹果#

放苹果

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

import java.util.*;
public class Main{
    public static int m;
    public static int n;
    public static int count;
    public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
       while(sc.hasNext()){
           m = sc.nextInt();
           n = sc.nextInt();
           count = 0;
           bfs(0,m,0);
           System.out.println(count);
       }
    }
    
    public static void bfs(int cur, int remainning, int curLen){
        if(curLen == n){
            if(remainning == 0){
                count++;
            }
            return;
        }
        for(int i = cur; i <= remainning; i++){
            bfs(i, remainning-i, curLen+1);
        }
    }
}

全部评论

相关推荐

牛马43373018...:这人真懂什么叫熵吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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