Description
牛客网 2018校招真题 倒水
Solving Ideas
问题可转化为将m个相同物体放入n个相同的容器中有多少种放法
Solution
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @author wylu
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int x = Integer.parseInt(br.readLine());
while (x-- != 0) {
String[] strs = br.readLine().split(" ");
int m = Integer.parseInt(strs[0]), n = Integer.parseInt(strs[1]);
System.out.println(func(m, n));
}
}
private static int func(int m, int n) {
if (m == 0 || n == 1) return 1;
if (n > m) return func(m, m);
else return func(m, n - 1) + func(m - n, n);
}
}