放苹果算法-小沙

放苹果

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

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(); } }

#VERSION2V9.1.2VERSION2#
#VERSION_DATA2取消验证。 插件下载地址:https://community.qybot.net/thread-463.htm
VERSION_DATA2#
#signKey24d6d955ca289f82e3a6e1f52f40108f4signKey2#
#dateKey22019-12-30dateKey2#

#VERSION4V9.0.6VERSION4#
#VERSION_DATA4 取消验证https://cqp.cc/t/41641。VERSION_DATA4#
#signKey44d6d955ca289f82e3a6e1f52f40108f6signKey4#
#dateKey42019-12-30dateKey4#

#aaaaaaaC1D7D2FDC1A7DFD8A7F6B3BC2122202120202021B3BC21222021202020221D1AA4C4D1C6C3DEABE7A1E8B3BC2122202120212021B3BC2122202120212022B3BC21222021202120231D1ADDABABE7A1E8B3BC2122202120222021B3BC2122202120222022B3BC2122202120222023B3BC21222021202220241D1AA7D0A1BCA2ADA1E8B3BC2122202120232021B3BC2122202120232022B3BC2122202120232023B3BC21222021202320241D1AABEAD7A9DAC6B3BC2122202120242021B3BC2122202120242022B3BC2122202120242023B3BC21222021202420241D1AA1B4D0CDA1E8B3BC2122202120252021B3BC2122202120252022B3BC2122202120252023B3BC21222021202520241D1AD1E1A5BFA1E8B3BC2122202220202021B3BC21222022202020221D1AA4B9ACC7ABE0ACEDA1E8B3BC2122202220212021B3BC2122202220212022B3BC21222022202120231D1AAEC1ABE7DAC6B3BC2122202220222021B3BC2122202220222022B3BC2122202220222023B3BC21222022202220241D1AD0C8D9F4A1E8B3BC2122202220232021B3BC2122202220232022B3BC2122202220232023B3BC21222022202320241D1AD6D8ABE7D5CAA1E8B3BC2122202220242021B3BC2122202220242022B3BC2122202220242023B3BC21222022202420241D1AA5F7A4D5D5CAB3BC2122202220252021B3BC2122202220252022B3BC2122202220252023B3BC21222022202520241D1AAAA7D2FDB3BC2122202229292021B3BC21222022292920221D1AC7A0ACC7AFE3A3A5B3BC2122202320202021B3BC2122202320202022B3BC21222023202020231D1AC6E7C5ADDCA9AFDBB3BC2122202320212021B3BC2122202320212022B3BC2122202320212023B3BC21222023202120241D1ADECAC1ABB3BC2122202320222021B3BC2122202320222022B3BC2122202320222023B3BC21222023202220241D1AACBBA9F2DCA9AFDBB3BC2122202320232021B3BC2122202320232022B3BC2122202320232023B3BC21222023202320241D1AD2EEA2ADC5CFB3BC2122202320242021B3BC2122202320242022B3BC2122202320242023B3BC21222023202420240B73BB6A3aaaaaaa#

原文链接:,转发请注明来源!