Lo-Keng Hua inequality and dynamic programming