poj-1664. put apples. (recursive)

Apple put

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 40548   Accepted: 24737

Description

The same apple on the M N number of the same plate, allowing some empty plates hold, ask how many different points system? (Represented by K) 5,1,1 and 1,5,1 points is the same method.

Input

The first row is the number of test data t (0 <= t <= 20). Each line contains the following two integers M and N, separated by spaces. 1 <= M, N <= 10.

Output

M and N for each set of data inputs, the output of the corresponding one line K.

Sample Input

1
7 3

Sample Output

8

Source

 

 

1  / * *********************************************** *************************
 2      > the Name File:. poj the 1664 release of Apple-.cpp
 3      > Author: CruelKing
 4      > Mail: 2,016,586,625 @ QQ .com 
 5      > the Created Time: 2019 Nian 09 Yue 09 Monday 20:14:27
 6      we dp [i] [j] represents the i j pieces of apple into a plate of
 7      this question ideas: when there are m pieces to put on the apple n disks, if m <n, then that there must be n - m a plate to be empty, the number of method is equivalent to dp [m] [m], is added at this time there is not at least one plate put Apple, then Apple is equivalent to m into n - 1 number plate, if the plate at this time all are put apples, so we can put each dish out an apple, that dp [m ] [n] is equivalent to dp [m - n] [n ]; when only one or no apple dish can put us return 1 there is a discharge method.
 8  ************* ************************************************** ******** * / 
. 9  
10 #include <cstdio>
 . 11  the using namespace std;
12 
13 int m, n;
14 
15 int dfs(int a, int b) {
16     if(b == 1 || a == 0) return 1;
17     if(a < b) return dfs(a, a);
18     else return dfs(a, b - 1) + dfs(a - b, b);
19 }
20 
21 int main() {
22     int t;
23     scanf("%d", &t);
24     while(t --) {
25         scanf("%d %d", &m, &n);
26         printf("%d\n", dfs(m, n));
27     }
28     return 0;
29 }

 

Guess you like

Origin www.cnblogs.com/bianjunting/p/11494177.html