Introduction to openjudge-Computing (A)-Putting apples

Source: Internet
Author: User

Describe:

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. The first line of input 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 to each set of data input m and n, with a row to output the corresponding K.

Sample input

17 3

Sample output

8

source [email protected]

Idea: A very classic topic, recursive, you can find the function between the law (very simple).

Recursive thinking: If the number of plates is larger than the number of apples, then there is nothing to say, the output can be, or continue to recursion until the number of plates is larger than the number of apples

This question is also the NOIP2014 popularization Group preliminary examination question Oh!

The code is as follows:

1#include <stdio.h>2 intFunintMintN)3 {4     if(m==0|| n==1)5         return 1; 6     if(n>m)7         returnFun (m,m);8     Else9         returnFun (m,n-1) +fun (M-n,n);Ten } One  A intMain () - { -     intK,m,n; thescanf"%d",&K); -      while(k--) -     { -scanf"%d%d",&m,&n); +printf"%d\n", Fun (m,n)); -     } +}

Introduction to openjudge-Computing (A)-Putting 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.