Put the Apples

Source: Internet
Author: User

Description

Topic description

Put m the same Apple on n same plate, allow some plates to be empty, ask how many different ways are there? (denoted by k) 5,1,1 and 1,5,1  are the same kind of sub-method.

 

Input

Each use case contains two integers m and N. 0<=m<=10,1<=n<=10. <=n<=10<=m<=10

 

Sample input

7 3

 

Sample output

8

     

/**

     *  calculate the number of ways to put apples


      *  returns 1

If the input value is illegal      * 1 <= m,n <=  10<><= m,n <= 10<>

     *  @param  m  number of apples

     *  @param  n  number of plates

      *  @return   Total number of placement methods

     * 

      */

    public static int count (int m, int  N)

 

 

 

Knowledge points Cycle
Run time limit 10M
Memory limit 128
Input

Enter a two int integer

Output

output result, int type

Sample input 3 ·
Sample output 8
Package Com.oj5;import Java.util.arraylist;import Java.util.list;import Java.util.scanner;public class Oj {static int Count;private static void Find (int[] flag,int pos,int applenum,int platenum,list List) {//system.out.println (appleNum+) "+platenum+" "+pos"); if (Pos==applenum) {int[] plates = new Int[platenum+1];for (int i = 0;i < Applenum; i++) plates[flag[i]]++;for (int i = 1; i<= plateNum-1; i++) for (int j = 1;j <= platenum-i; j + +) if (plates[j]<plates[j +1] {int temp = Plates[j];p lates[j] = plates[j+1];p lates[j+1] = temp;} Boolean isexist = false; for (int i = 0;i < List.size (); i++) {int[] arr = (int[]) list.get (i); int j = 1;for (; j <= Platenum; j + +) if (plates[j]!= ARR[J]) break;if (j==platenum+1) {isexist = True;break;}} if (!isexist) list.add (plates); return;} for (int i = 1;i <= platenum; i++) {Flag[pos] = I;find (flag,pos+1,applenum,platenum,list);}} public static void Main (string[] args) {Scanner in = new Scanner (system.in), int applenum = In.nextint (); int platenum = in. Nextint (); int[] flag = new Int[applenum]; list<integer[]> list = new arraylist<integer[]> (); find (flag,0,applenum,platenum,list); System.out.println (List.size ());}}

  

Put the 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.