'commit'
This commit is contained in:
33
TangDou/Dfs/DFS11_ZhengShuChaiFen.cpp
Normal file
33
TangDou/Dfs/DFS11_ZhengShuChaiFen.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
vector<int> a;
|
||||
int m;
|
||||
int cnt;
|
||||
|
||||
/**
|
||||
* 功能:整数的拆分
|
||||
* @param n 要拆分的数
|
||||
*/
|
||||
void dfs(int n) {
|
||||
if (n == 0 && a.size() > 1) {
|
||||
for (int i = 0; i < a.size(); i++) printf("%d ", a[i]);
|
||||
printf("\n");
|
||||
cnt++;
|
||||
return;
|
||||
}
|
||||
// a 2 3 4 ->5 6 7
|
||||
for (int i = a.size() == 0 ? 1 : a[a.size() - 1]; i <= n; i++) {
|
||||
a.push_back(i);
|
||||
dfs(n - i);
|
||||
a.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> m;
|
||||
dfs(m);
|
||||
//总数量
|
||||
printf("%d ", cnt);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user