simple DP, linked list, array