sum of powers dp version