【正经题解】数的划分
2024-02-21 17:54:54
发布于:浙江
13阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
int ans = 0;
// 递归搜索每一种分法
void dfs(int a, int b, int c) {
if (c == m) {
if (b == n) {
ans++;
}
return;
}
for (int i = a; b + i * (m - c) <= n; i++) {
dfs(i, b + i, c + 1);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> m;
dfs(1, 0, 0);
cout << ans << endl;
return 0;
}
这里空空如也
有帮助,赞一个