You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
850 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
int t, a, b;
vector<vector<int>> result;
vector<int> path;
//代码随想录,回溯法
void backtracking(int n, int k) { // 定义手中有n个笔记本正在为第k个人发笔记本
if (n == 0 || k == a + 1) {
if (n == 0) result.push_back(path);
return; //没有笔记本可以分,或者没有孩子可以分了,就结束吧
}
//开始分发
for (int i = 0; i <= n; i++) {
path.push_back(i);
//分配给当前人i个然后走向下一个小朋友
backtracking(n - i, k + 1);
path.pop_back();
}
}
int main() {
cin >> t >> a >> b;
//剩余需要分配的个数
int n = t - a * b;
//回溯法
backtracking(n, 1);
cout << result.size() << endl;
return 0;
}