-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecomposition_sum.cpp
More file actions
53 lines (46 loc) · 949 Bytes
/
decomposition_sum.cpp
File metadata and controls
53 lines (46 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <queue>
#include <math.h>
using namespace std;
int N;
int C;
deque<int> ans;
deque<int> a;
//input = a+b+c+a*100+b*10+c (0<a<=0 && 0<=b<=9 && 0<=c<=9)
//output = a*100+b*10+c;
void dfs(int candi, int index, int cnt){
if(cnt == C ){
if(candi == N){
if(ans.size()==0){
ans = a;
}
}
return;
}else{
for(int i = 0; i<10;i++){
int tmp = candi + (pow(10, C-cnt-1) * i) + i;
if(tmp<=N){
a.push_back(i);
dfs(tmp, i, cnt+1);
a.pop_back();
}
}
}
}
int main()
{
cin >> N;
C = log10(N)+1;
dfs(0, 0, 0);
if(ans.size()==0){
cout<<0;
return 0;
}
for(int i = 0; i<ans.size();i++){
if(ans[i]==0 && i==0){
continue;
}
cout << ans[i];
}
return 0;
}