Search for acm1664

Source: Internet
Author: User

Put Apple
Description

Put M identical apples on N identical dishes, and some are allowed to leave them empty. How many different methods are there? (Expressed in K) 5, 1, 1, and 1, 5, 1 are the same 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 spaces. 1 <= m, n <= 10.

Output

Output the corresponding K in one row for each group of input data M and N.

Sample Input

 
17 3

Sample output

 
8

Source

Search for the given apple in sequence, and make statistics on the status that meets the conditions. You can.
CodeAs follows:

# Include < Stdio. h >
Int Total = 0 ;
Int M, n, h;
Void Solve ( Int X, Int K)
{
Int I, J;
If (H = 0 && K <= N)
{
Total++;
Return;
}
If (K = N) Return ;
Else
{
For (I = X; I > = 1 ; I -- )
{

If (I <= H)
{
H=H-I;
Solve (I, K+1);
H=H+I;
}
}
}
}
Main ()
{
Int Count;
Scanf ( " % D " , & Count );
While (Count -- )
{
Scanf ( " % D " , & M, & N );
H = M;
Total = 0 ;
Solve (m, 0 );
Printf ( " % D \ n " , Total );
}
}

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.