Routing problem is one of the most important issues to a wireless sensor network (WSN), and multi-hop transmission is one of its characteristics, so the idea of dynamic programming (DP) is very suitable for routing problem of a WSN. Based on dynamic programming, we propose an efficient energy routing algorithm. In this algorithm, we firstly propose an energy consumption model of sensor nodes and a method to transform WSN structure into standard DP model. Next we put forward a routing algorithm with minimal energy expends according to the DP model. Finally, in order to balance energy expends and to prolong the network lifetime, we adjust its set of state variable on the basis of average residual energy of each stage in the DP model. Experiments indicate that our algorithm has more efficient energy expends and a longer lifespan.