View Code of Problem 787

#include <iostream>
#include <cstdio>
using namespace std;
int f(int m,int n){
    if(n>m)
        return f(m,m);//f(m,n)==f(m,m);盘子多水果少
    if(m==0)
        return 1;
    if(n==0)
        return 0;
    return f(m,n-1)+f(m-n,n);//每次空一个盘子的放法+每次不空盘子
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int M,N;
        cin>>M>>N;
        cout<<f(M,N)<<endl;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 787