{"trustable":true,"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":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eThis is a simple problem about string. Now a string S contains only ‘0’-‘9’. ?? wants to select a subsequence from this string. And makes this subsequence score maximum. The subsequence’s score is calculated as follows:\u003cbr\u003e Score\u003d Value – Total_Cost\u003cbr\u003e The calculation of the Cost is as follows:\u003cbr\u003e If the number of characters x in the subsequence is kx, And the two coefficients are ax,bx,The cost of character x calculated as follows:\u003cbr\u003e\u003cbr\u003e\u003cbr\u003e$$ \\left\\{\\begin{matrix}\\\\cost[x]\u003d0,kx\u003d0\\\\ cost[x]\u003dax*(kx-1)+bx,kx\\ne0\\\\\\\\\\end{matrix}\\right.$$\u003cbr\u003e $$TotalCost\u003d\\sum_{i\u003d0}^{9}cost[i]$$\u003cbr\u003e The calculation of the Value is as follows:\u003cbr\u003e\u003cpre\u003e\u003cbr\u003eValue\u003d0;\u003cbr\u003efor(int i\u003d1;i\u0026lt;\u003dlength(substr);++i){\u003cbr\u003e for(int j\u003d1;j\u0026lt;\u003dlength(substr);++j){\u003cbr\u003e if(i!\u003dj)\u003cbr\u003e Value+\u003dw[id[i]][id[j]];\u003cbr\u003e }\u003cbr\u003e}\u003cbr\u003e\u003c/pre\u003e\u003cbr\u003e id[i] is the position of the subsequence’s ith character in the original string,for example,if the original string is “13579”,and the subsubquence is “159”,then the array id \u003d{1,3,5}. The w is a weight matrix.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line contains an integer T, denoting the number of the test cases.\u003cbr\u003eFor each test case, the first line contains one integers n, the length of a string.\u003cbr\u003eNext line contains the string S.\u003cbr\u003eNext ten lines,each line contains ai,bi,denote the char i’s(0-9) coefficients\u003cbr\u003eNext is a n*n matrix w.\u003cbr\u003eLimits:\u003cbr\u003eT\u0026lt;\u003d20,\u003cbr\u003e0\u0026lt;\u003dn\u0026lt;\u003d100\u003cbr\u003e0\u0026lt;\u003dai\u0026lt;\u003dbi\u0026lt;\u003d1000\u003cbr\u003e0\u0026lt;\u003dw[i][j]\u0026lt;\u003d50\u003cbr\u003e\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"Each test output one line “Case #x: y” , where x is the case number ,staring from 1. y is the Maximum score.\u003cbr\u003e"}},{"title":"Sample","value":{"format":"HTML","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\r\n3\r\n135\r\n1 2\r\n1 2\r\n1 2\r\n1 2\r\n1 2\r\n1 2\r\n1 2\r\n1 2 \r\n1 2\r\n1 2\r\n0 0 3\r\n1 0 0\r\n4 0 0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase #1: 3\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"we can choose “15”,id[]\u003d{1,3} then Value\u003dw[1][3]+w[3][1]\u003d7,\u003cbr\u003eTotal_Cost\u003d2+2\u003d4,Score\u003d7-4\u003d3\u003cbr\u003e"}}]}