A trie is a tree where every node represents a prefix of a string. When a string ss is…
- User
A trie is a tree where every node represents a prefix of a string. When a string ss is inserted into a trie, up to ∣s∣+1∣s∣+1 nodes are created if they don't already exist:
codea node representing the empty string, '', which is always the root of the trie a node representing the first character of ss, which is a child of the root a node representing the first two characters of ss, which is a child of the previous node ... and so onYou have NN wildcard strings, S1S1 through SNSN, which each consist of uppercase Latin letters and question marks. A wildcard string represents the set of all strings that you can create by replacing each question mark with some uppercase Latin letter. If you add every string represented by each of your wildcard strings to a single trie (initially empty), how many nodes will that trie have? Output this number modulo 998,244,353998,244,353. Constraints 1≤T≤1051≤T≤105 1≤N≤251≤N≤25 1≤∣Si∣≤1001≤∣Si∣≤100 All characters are uppercase Latin letters or question marks. Input Format Input begins with an integer TT, the number of test cases. Each case begins with a line that contains the integer NN. Then NN lines follow, the iith of which contains the string SiSi. Output Format For the iith test case, print "Case #i: " followed by the number of nodes in the resulting trie, modulo 998,244,353998,244,353. Sample Explanation In the first case, we insert the string META into the trie, creating 55 nodes: [[ '', M, ME, MET, META ]]. Inserting MATE would create the 55 nodes [[ '', M, MA, MAT, MATE ]], but those first 22 nodes already exist, so 33 new nodes are created. In the end we have 88 nodes. In the second case, we insert the strings [[ AB, BB, CB, ... ZB ]] into the trie, which creates the 5353 nodes [[ '', A, AB, B, BB, ..., Z, ZB ]]. When we add the string AC, that creates one new node, AC. In the third case, we insert all combinations of 22 letters, giving us 11 node for the empty string, 2626 nodes for the single letters, and 26×26=67626×26=676 nodes for the pairs of letters, for a total of 703703 nodes.
- Assistant