-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumCube.cpp
More file actions
67 lines (58 loc) · 1.37 KB
/
SumCube.cpp
File metadata and controls
67 lines (58 loc) · 1.37 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <map>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#define M_SIZE 100000
using namespace std;
int dp[M_SIZE];
int temp;
map<int, pair<int,int> > parent;
int index1, index2 = 0;
int counter, query;
void display(int query, map<int, pair<int, int> > parent)
{
cout << parent[query].second << "^3";
counter = parent[query].first;
while (counter>0)
{
cout << " + " << parent[counter].second << "^3";
counter = parent[counter].first;
}
}
int main()
{
dp[0] = 1;
parent[1].first = 0;
parent[1].second = 1;
for (int i = 1; i < M_SIZE; i++)
{
dp[i] = i;
}
for (int i = 2; i < M_SIZE; i++)
{
index1, index2 = 0;
for (int j = 1; j < M_SIZE; j++)
{
temp = j*j*j;
if( temp > i)
break;
if (dp[i] >= dp[i-temp] + 1)
{
dp[i] = dp[i-temp] + 1;
index1 = i-temp;
index2 = j;
}
}
parent[i].first = index1;
parent[i].second = index2;
//cout << "number : " << i << " --> " << dp[i] << endl;
}
cin >> query;
if (cin.good())
display(query, parent);
else
cout << "Enter number" << endl;
return 0;
}