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;