Minimize total affinity of class

So i have been trying to solve this question:

there are “n” students in a class and student “i” has an affinity with student “j”, denoted by k[i,j] where i != j. The objective is to determine the order in which students stand to minimize the total affinity of the class. Here, the total affinity is defined as the sum of affinities of continuous student pairs.

I know this needs a DP approach but I am stuck at this point.

//