How can you calculate the shortest chain of addition (sac) for an arbitrary n <= 600 in one second?
Notes
This month's codility programming competition .
Additive chains are very important because they are the most economical way to calculate x ^ n (sequential multiplications).
Knuth The Art of Computer Programming, Volume 2, Seven-Dimensional Algorithms has a good understanding of additive chains and some interesting properties, but I didn’t know anything that allowed me to meet strict performance requirements.
( )
-, ( ) ( 1- > 2 → (3 → ..., 4 → ...)) , node n, n n. > 400 , .
, . 600, . n n. , ...
NP-hard, . , , , . .
Update
, , , , / / ?