| 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