Peking University written test--Put apples

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.