Solve partition key with DP approach