`
vcdemon
  • 浏览: 19513 次
社区版块
存档分类
最新评论
  • djx410249: 简单的自己想了几个数字测试了下,发现这个数会在经过几次跳动之后 ...
    3n+1
  • I白I: 怎么回事,好多字都卡在外面了 不显示。。。还要查看源代码看内容 ...
    3n+1

放苹果

    博客分类:
  • java
阅读更多
放苹果
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 25550   Accepted: 16249

Description

把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法。

Input

第一行是测试数据的数目t(0 <= t <= 20)。以下每行均包含二个整数M和N,以空格分开。1<=M,N<=10。

Output

对输入的每组数据M和N,用一行输出相应的K。

Sample Input

1
7 3

Sample Output

8

 

<pre name="code" class="java">import java.util.Scanner;  
  
public class Main {  
      
    public static int Test(int m, int n) {  
        if (m == 0 || n == 1) {  
            return 1;   
        }  
        if (n > m) {  
            return Test(m, m);  
        } else {  
            return Test(m, n - 1) + Test(m - n, n);  
        }  
    }  
  
    public static void main(String[] args) {  
        Scanner cin = new Scanner(System.in);  
        int i = cin.nextInt();  
        for (int j = 0; j < i; j++) {  
            int m = cin.nextInt();  
            int n = cin.nextInt();  
            System.out.println(Test(m, n));  
        }  
        cin.close();  
    }  
}  

 

1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics