Let i represent the index (num in your example) and j represent the actual word c represent all the letters ('A'..'Z') Let X[i,j] = { 1 if word (i,j) was chosen, 0 otherwise} The value of each word can be broken into characters/letters For all (i, j) - # you get the value only if the word is chosen V[i,j,c] = number of c's in the word (i,j) * X[i,j] For all c Let Value(c) = (sum {over all i,j} V[i,j,c])*((sum {over all i,j} V[i,j,c])+1)/2 Optimization problem =================== Max sum {over c} Value(c) # You can choose only one word from each index (num) subject to: sum {over all j} X[i,j] = 1 for all i. subject to: x[i,j] element of (0,1) for all i, j.