将整数N分成K个整数的和且每个数大于等于A 小于等于B 求有多少种分法?
代码如下:
#include <iostream>
using namespace std;int fff(int a, int k, int mins, int maxs) {if (a < mins)//结束条件有两个,1.数值小于最小值 2.只分成一个数return 0;if (k == 1)return 1;int res = 0;for (int i = mins; i <= maxs; i++) {res += fff(a - i, k - 1, i, maxs);}return res;
}int main() {int n, k, mins, maxs;cin >> n >> k >> mins >> maxs;cout << fff(n, k, mins, maxs) << endl;return 0;
}