Is it possible to assume that the dictionary is fixed, and the score is fixed and that only the available letters will change (as in scrabble)? Otherwise, I think itβs better not to look at every word of the dictionary, as suggested earlier.
So, let's say that we are in this setting. Select order <for letter costs. For example, Q> Z> J> X> K> ..> A> E> I ..> U.
Replace the dictionary D with the dictionary D 'made up of anagrams of the words D with letters ordered in the previous order (for example, the word buzz is displayed on zzbu), as well as deleting duplicates and words of length> 8, if you have no more than 8 letters.
Then build a trie with the words D ', where the child nodes are ordered by the value of their letters (so the first descendant of the root will be Q, the second Z, .., the last child U). On each node trie also keep the maximum value of the word passing through this node.
Given the set of available characters, you can first examine the trie in depth, moving from left to right and storing the current best value in memory. Examine the branches, the value of node is greater than the current best value. Thus, you will study only a few branches after the first (for example, if you have Z in your game, any branch starting with the letter of one point is examined when A is discarded, because it will pick up no more than 8x1, which is less than Z) . I bet you will only explore a few branches each time.
source share