a typical DP problem