Reprint Please specify source: http://blog.csdn.net/u012860063?viewmode=contents
Title Link: http://poj.org/problem?id=1664
Description
Put m the same apples on n the same plate, allow some plates to be empty, ask how many different ways? (denoted by k) 5,1,1 and 1,5,1 are the same kind of sub-method.
Input
The first line is the number of test data t (0 <= T <= 20). Each of the following lines contains two integers m and n, separated by a space. 1<=m,n<=10.
Output
For each set of data entered M and N, the corresponding k is output in one line.
Sample Input
17 3
Sample Output
8
The code is as follows:
① the least plate for one, then is left m-n apples on n plates//② the minimum plate is empty, then is the M Apple on the remaining n-1 plate # # <iostream> #include <cstring> Using namespace Std;int dp[21][21];int f (int m, int n) {if (M < 0) return 0;if (M = = 0 | | n = = 1) return 1;if (Dp[m][n]) retur n Dp[m][n];dp [m][n] = f (m-n,n) +f (m,n-1); return dp[m][n];} int main () {int n, m;int t;while (cin >>t) {while (t--) {Cin>>m>>n;memset (dp,0,sizeof (DP));DP [m][n] = f ( M,n); Cout<<dp[m][n]<<endl;}} return 0;}