---
title: "放苹果"
author: "vcdemon"
date: "2014-06-19T13:43:59Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2014-06-19T13:43:59Z"
id: 2082534
url: "https://tbk.iteye.com/blog/2082534"
---

放苹果

**Time Limit:** 1000MS   **Memory Limit:** 10000K **Total Submissions:** 25550   **Accepted:** 16249

Description

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

Input

第一行是测试数据的数目t（0 &lt;= t &lt;= 20）。以下每行均包含二个整数M和N，以空格分开。1&lt;=M，N&lt;=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();  
    }  
}  
```