The title describes how many different kinds of sub-methods are available when the M-identical apples are placed on n identical plates, allowing some plates to be left empty.
http://www.nowcoder.com/practice/a96b78e871c347bbb8cadf7bea0ee862?tpId=40&tqId=21395&rp=1&ru=/ta/ Kaoyan&qru=/ta/kaoyan/question-ranking
Ideas:
N Plates put m in two mutually exclusive cases
① no plates for 0, at least 1 per plate, equal to n plates and m-n.
② has 0 plates, which is equal to N-1 a plate of M-a
Package Com.tonyluis.oj;import java.util.*;p ublic class Main {public static void main (string[] args) {@SuppressWarnings ( "Resource") Scanner in = new Scanner (system.in), while (In.hasnext ()) {int Apple = In.nextint (); int cup = In.nextint (); System.out.println (Calc (Apple, cup));}} static int calc (int apple, int cup) {if (Apple < 0) return 0;else if (Apple <= 1 | | cup = = 1) return 1;return Calc (app Le, cup-1) + calc (Apple-cup, cup);}}
Peking University written test--Put apples