acwing 1050. 鸣人的影分身

acwing 1050. 鸣人的影分身

image-20230315211712845

思路:

image-20230315212046039

代码:

#include <iostream>
#include <algorithm>
using namespace std;
const int N = 25;
int m, n;
int t, res;

int f(int a, int b)
{
    if (a == 0)   // 火影的能量值分完了 -- 》表示该方法可行---> 记录为一条通路
        return 1;
    if (b == 0)     // 如果火影的能量值有剩余,但是火影需要分配的人数已经分完了-- 》 说明这条路不通
        return 0;
    if (a < b) // 火影的能量值完全不能满足的时候,那么100%需要有人能量值为0
    {
        return f(a, a);  // 那么我就不考虑多出来的了
    }
    else
    {
        return f(a - b, b) + f(a, b - 1);   // 火影的能量值可以满足的时候,只需要考虑剩下的人,有没有为0的情况
    }
}

int main()
{
    cin >> t;

    while (t--)
    {
        cin >> m >> n;
        res = f(m, n);
        cout << res << endl;
    }
}