F-Small Sunny teacher series--Apple Bumper Harvest

Source: Internet
Author: User

F-Small sunny teacher series--Apple Bumper HarvestTime Limit:2000/1000ms (java/others) Memory Limit: 128000/64000kb (java/others) Submit Statusproblem Description

Small sunny back garden there are many apple trees, one day, Apple bumper harvest ~ Small Sunny A total of picking m apples, we assume that the apple is indistinguishable.

In order to save apples, a small sunny day to buy n an identical box, want to put the apple in, allow some boxes is empty, how many different ways to put a small sunny day?

For example, for 4 apples, 3 chests, 2+1+1 and 1+2+1, and 1+1+2 are the same kind of sub-method.

Input

Multiple sets of data, first, a positive integer t (t<=100) that represents the number of groups of data.

Each group of data contains two integers M and N (1<=m,n<=10).

Output for each set of data, outputs an integer that represents a different number of methods of discharge. Sample Input
17 3
Sample Output
8
Hint

For 7 apples, 3 boxes

Have 7+0+0=6+1+0=5+2+0=4+3+0=5+1+1=4+2+1=3+2+2=3+3+1

These 8 kinds of methods.

Idea: This is the same as the previous one, but this is the topic of violence, the use of violent methods.

Put the apples in every way, from as many as one time,

For example, 7 3, the words are:

7 0 0

6 1 0

5 2 0

5 1 1

4 3 0

4 2 1

3 3 1

3 2 2

is not found out what the law, from the left to the right in descending order, and the sum will be equal to M, and the number of numbers can not exceed N, the violence resolved:

1#include <iostream>2#include <stdio.h>3 using namespacestd;4 intM,n;5 intSUM;6 voidBFS (intSumintJintNum)/*BFS (i,j,k), I represents the sum of the current number,*/7{/*J marks the number of digits, K indicates the current number*/8     inti;9     if(j<=n&&sum==m) {sum++;return;}/*sum equal to m and number less than n is a method*/Ten      for(i=num;i>0; i--)/*each time the number is less than or equal to the current number*/ One     { A         if(sum+i<=m)/*determine if the sum is exceeded*/ -         { -BFS (sum+i,j+1, i); the         } -     } - } - intMain () + { -     inti,t; +scanf"%d",&T); A      while(t--) at     { -scanf"%d%d",&m,&N); -sum=0; -          for(i=m;i*n>=m;i--) -         { -BFS (I,1, i);  in         } -printf"%d\n", SUM); to     } +     return 0; -}
View Code

One of the previous topics put apples: http://www.cnblogs.com/LWF5201314614/p/3750313.html

F-Small Sunny teacher series--Apple Bumper Harvest

Related Article

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.