Description
牛客网 校招真题 倒水
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);}}
如果觉得《牛客网 校招真题 贝壳找房 倒水》对你有帮助,请点赞、收藏,并留下你的观点哦!