title Description: Put m apples on n plates, can have plates empty, but no order, for example, 5 apples to 3 plates, 1+1+3 and 1+3+1 as the same method, the total number of methods.
Dynamic Planning * * * *
ImportJava.util.Scanner;2 Public classmain{3 Public Static voidMain (string[] args)4 {5 /*6 * with dp[i][j] means the number of ways I apples are placed on the J plate7 *i an Apple into a J-plate (no order) in two cases8 * * There is a tray empty (this situation contains multiple plates for empty condition)9 * method number is dp[i][j-1]Ten all dishes are not empty, then each plate has at least one apple, the remaining One *i-j apples are placed on a J plate, the number of methods is dp[i-j][j] A * then dp[i][j] = Dp[i][j-1]+dp[i-j][j] - (also consider when J>i, Dp[i][j]=dp[i][i]) - */ theScanner sc =NewScanner (system.in); - while(Sc.hasnext ()) - { - intM =sc.nextint (); + intN =sc.nextint (); - int[] DP =New int[M+1] [N+1]; + for(inti=1;i<=n;i++) A { atDp[1][i]=1; -Dp[0][i]=1; - } - for(inti=1;i<=m;i++) - { -Dp[i][1]=1; inDp[i][0]=0; - } to for(inti=2;i<=m;i++) + { - for(intj=2;j<=n;j++) the { * if(i>=j) $DP[I][J] = dp[i][j-1]+dp[i-J] [j];Panax Notoginseng Else -dp[i][j]=Dp[i][i]; the } + } A System.out.println (Dp[m][n]); the } + } -}
The Apple of dynamic planning