Skip to content

Latest commit

 

History

History
59 lines (47 loc) · 1.04 KB

1664.md

File metadata and controls

59 lines (47 loc) · 1.04 KB

返回

放苹果

Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 34314 Accepted: 21245

Description

  • 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法。

Input

  • 第一行是测试数据的数目t(0 <= t <= 20)。以下每行均包含二个整数M和N,以空格分开。1<=M,N<=10。

Output

  • 对输入的每组数据M和N,用一行输出相应的K。

Sample Input

1
7 3

Sample Output

8
#include <iostream>


using namespace std;

int di(int a,int b){
    if(a==1||b==1){
        return 1;
    }
    if(a>b){
        return di(a-b,b)+di(a,b-1);
    }
    if(a==b){
        return 1+di(a,b-1);
    }
    if(a<b){
        return di(a,a);
    }

}

int main(){
    int n,a,b;
    cin>>n;
    while(n--){
        cin>>a>>b;
        cout<<di(a,b)<<endl;
    }


    return 0;
}

返回