c++ - How to find the largest sum with the smallest possible path in a tetrahedron of integers? -


first here question,

say integer can represented perfect sphere, in value of sphere equal integer contains. spheres organized tetrahedral pyramid in n = length of side, n being between 1 , 15. pick (a possibly empty) subset of sphere's such sum of values maximized. note sphere can hold negative value not desirable pick every sphere. not want disorganize pyramid cannot take 1 sphere without first taking ones above it.

input format:

line 1: integer n

line 2: n(n+1)/2+1

output format:

line 1: 1 integer, maximum sum of values achievable

sample input:

3 5 -2 -7  -3 1 0 8 0 3 2 

sample output:

8 

here sample solution given understanding far:

the best solution shown bold in diagram bellow. not smart take 1 because require taking -2, decreasing total. there 8, 3, , 2 should taken because outweigh -3 , -7.

sample diagram of tetrahedron

my question is,

how store input can retain proper order? or need to? trying use queue program gets lengthly because have find sum each possible path , compare each sum find max. having lot of difficulty breaking data right pattern don't recount number or take 1 out of sequence. there more efficient way this? can dijkstra's algorithm of use in case? if so, how? appreciated!!

i use 3-dimensional array. use example:

a[0][0][0] = 5  a[1][0][0] = -2 a[1][1][0] = -3 a[1][0][1] = -7  a[2][0][0] = 1 a[2][1][0] = 0 a[2][2][0] = 2 a[2][0][0] = 0 a[2][1][0] = 3 a[2][0][0] = 8 

the "above" relationship matter of index arithmetic: [ia, ja, ka] above [ia+1, ja, ka], [ia+1, ja+1, ka] , [ia+1, ja, ka+1].


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -