{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"MD","content":"给定一个单词列表,以及每个单词的分值。\n\n要求选择一个单词子序列,使得相邻的两个单词满足**前一个是后一个的子串**,且分数总和尽量大。\n\n输出最大的分数。\n\n---\n\n\u003cdiv class\u003d\"panel_content\"\u003e\n Recently George is preparing for the Graduate Record Examinations (GRE for short). Obviously the most important thing is reciting the words.\n \u003cbr\u003e\n Now George is working on a word list containing N words.\n \u003cbr\u003e\n He has so poor a memory that it is too hard for him to remember all of the words on the list. But he does find a way to help him to remember. He finds that if a sequence of words has a property that for all pairs of neighboring words, the previous one is a substring of the next one, then the sequence of words is easy to remember.\n \u003cbr\u003e\n So he decides to eliminate some words from the word list first to make the list easier for him. Meantime, he doesn\u0027t want to miss the important words. He gives each word an importance, which is represented by an integer ranging from -1000 to 1000, then he wants to know which words to eliminate to maximize the sum of the importance of remaining words. Negative importance just means that George thought it useless and is a waste of time to recite the word.\n \u003cbr\u003e\n Note that although he can eliminate any number of words from the word list, he can never change the order between words. In another word, the order of words appeared on the word list is consistent with the order in the input. In addition, a word may have different meanings, so it can appear on the list more than once, and it may have different importance in each occurrence.\n \u003cbr\u003e\n \u003ccenter\u003e\n \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/2ac7f26b6d65a5b92194ec3edda62a8e?v\u003d1693526194\"\u003e\n \u003c/center\u003e\n\u003c/div\u003e"}},{"title":"Input","value":{"format":"MD","content":"The first line contains an integer T(1 \u0026lt;\u003d T \u0026lt;\u003d 50), indicating the number of test cases.\n\u003cbr\u003e\nEach test case contains several lines.\n\u003cbr\u003e\nThe first line contains an integer N(1 \u0026lt;\u003d N \u0026lt;\u003d 2 * 10\u003csup\u003e4\u003c/sup\u003e), indicating the number of words.\n\u003cbr\u003e\nThen N lines follows, each contains a string S\u003csub\u003ei\u003c/sub\u003e and an integer W\u003csub\u003ei\u003c/sub\u003e, representing the word and its importance. S\u003csub\u003ei\u003c/sub\u003e contains only lowercase letters.\n\u003cbr\u003e\nYou can assume that the total length of all words will not exceeded 3 * 10\u003csup\u003e5\u003c/sup\u003e."}},{"title":"Output","value":{"format":"MD","content":"For each test case in the input, print one line: \"Case #X: Y\", where X is the test case number (starting with 1) and Y is the largest importance of the remaining sequence of words."}},{"title":"Sample","value":{"format":"MD","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1\n5\na 1\nab 2\nabb 3\nbaba 5\nabbab 8\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase #1: 14\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}