mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 17:56:28 +00:00
P2404 自然数的拆分问题
R52333755
This commit is contained in:
parent
a21741c55a
commit
9e5aa29038
28
Luogu/problem/P2404/P2404.cpp
Normal file
28
Luogu/problem/P2404/P2404.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int n, a[10];
|
||||
|
||||
void dfs(int x, int depth, int last) {
|
||||
if (x > n) return;
|
||||
if (x == n) {
|
||||
for(int i = 1 ; i < depth - 1 ; i++) {
|
||||
cout << a[i] << '+';
|
||||
}
|
||||
cout << a[depth-1] << endl;
|
||||
return;
|
||||
}
|
||||
for (int i = last; i < n; i++) {
|
||||
a[depth] = i;
|
||||
dfs(x + i, depth + 1, i);
|
||||
a[depth] = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
dfs(0, 1, 1);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user