initial try for together till the end using dynamic prog