{"trustable":false,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n section pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"Problem Statement","value":{"format":"HTML","content":"你面前有一堵墙,墙上有数字,你需要将墙上的数字都变成 1 。\n现在给出一个 W×H 的矩阵 A 表示墙上数字的情况。\n其中若\\(A_{i,j}\u003d-1\\),则表示位置 (i,j)上没有数字,否则 \\(A_{i,j}\\)的值表示墙上 (i,j) 位置的数字。\n当然,你还有一张 10×10 的表 C,其中\\(c_{i,j}\\)表示把数字 i 转化成数字 j 所需要的花费。\n求花费的最小值。"}},{"title":"Constraints","value":{"format":"HTML","content":"\u003csection\u003e\n \u003cul\u003e\n \u003cli\u003e\u003cvar\u003e\\(1≤H,W≤200\\)\u003c/var\u003e\u003c/li\u003e\n \u003cli\u003e\u003cvar\u003e\\(1≤c_{i,j}≤10^3\\)\u003c/var\u003e \u003cvar\u003e\\((i≠j)\\)\u003c/var\u003e\u003c/li\u003e\n \u003cli\u003e\u003cvar\u003e\\(c_{i,j}\u003d0\\)\u003c/var\u003e \u003cvar\u003e\\((i\u003dj)\\)\u003c/var\u003e\u003c/li\u003e\n \u003cli\u003e\u003cvar\u003e\\(-1≤A_{i,j}≤9\\)\u003c/var\u003e\u003c/li\u003e\n \u003cli\u003eAll input values are integers.\u003c/li\u003e\n \u003cli\u003eThere is at least one digit on the wall.\u003c/li\u003e\n \u003c/ul\u003e\n\u003c/section\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003csection\u003e\n \u003cp\u003eInput is given from Standard Input in the following format:\u003c/p\u003e\n \u003cpre\u003e\u003cvar\u003e\\(H\\)\u003c/var\u003e \u003cvar\u003e\\(W\\)\u003c/var\u003e\n\u003cvar\u003e\\(c_{0,0}\\)\u003c/var\u003e \u003cvar\u003e\\(...\\)\u003c/var\u003e \u003cvar\u003e\\(c_{0,9}\\)\u003c/var\u003e\n\u003cvar\u003e\\(:\\)\u003c/var\u003e\n\u003cvar\u003e\\(c_{9,0}\\)\u003c/var\u003e \u003cvar\u003e\\(...\\)\u003c/var\u003e \u003cvar\u003e\\(c_{9,9}\\)\u003c/var\u003e\n\u003cvar\u003e\\(A_{1,1}\\)\u003c/var\u003e \u003cvar\u003e\\(...\\)\u003c/var\u003e \u003cvar\u003e\\(A_{1,W}\\)\u003c/var\u003e\n\u003cvar\u003e\\(:\\)\u003c/var\u003e\n\u003cvar\u003e\\(A_{H,1}\\)\u003c/var\u003e \u003cvar\u003e\\(...\\)\u003c/var\u003e \u003cvar\u003e\\(A_{H,W}\\)\u003c/var\u003e\n\u003c/pre\u003e\n\u003c/section\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003csection\u003e\n \u003cp\u003ePrint the minimum total amount of MP required to turn every digit on the wall into \u003cvar\u003e\\(1\\)\u003c/var\u003e in the end.\u003c/p\u003e\n\u003c/section\u003e"}},{"title":"Sample 1","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\u003e2 4\n0 9 9 9 9 9 9 9 9 9\n9 0 9 9 9 9 9 9 9 9\n9 9 0 9 9 9 9 9 9 9\n9 9 9 0 9 9 9 9 9 9\n9 9 9 9 0 9 9 9 9 2\n9 9 9 9 9 0 9 9 9 9\n9 9 9 9 9 9 0 9 9 9\n9 9 9 9 9 9 9 0 9 9\n9 9 9 9 2 9 9 9 0 9\n9 2 9 9 9 9 9 9 9 0\n-1 -1 -1 -1\n8 1 1 8\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e12\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003csection\u003e\n\u003c/section\u003e\u003csection\u003e\n \u003cp\u003eTo turn a single \u003cvar\u003e\\(8\\)\u003c/var\u003e into \u003cvar\u003e\\(1\\)\u003c/var\u003e, it is optimal to first turn \u003cvar\u003e\\(8\\)\u003c/var\u003e into \u003cvar\u003e\\(4\\)\u003c/var\u003e, then turn \u003cvar\u003e\\(4\\)\u003c/var\u003e into \u003cvar\u003e\\(9\\)\u003c/var\u003e, and finally turn \u003cvar\u003e\\(9\\)\u003c/var\u003e into \u003cvar\u003e\\(1\\)\u003c/var\u003e, costing \u003cvar\u003e\\(6\\)\u003c/var\u003e MP.\u003c/p\u003e\n \u003cp\u003eThe wall contains two \u003cvar\u003e\\(8\\)\u003c/var\u003es, so the minimum total MP required is \u003cvar\u003e\\(6×2\u003d12\\)\u003c/var\u003e.\u003c/p\u003e\n\u003c/section\u003e"}},{"title":"Sample 2","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\u003e5 5\n0 999 999 999 999 999 999 999 999 999\n999 0 999 999 999 999 999 999 999 999\n999 999 0 999 999 999 999 999 999 999\n999 999 999 0 999 999 999 999 999 999\n999 999 999 999 0 999 999 999 999 999\n999 999 999 999 999 0 999 999 999 999\n999 999 999 999 999 999 0 999 999 999\n999 999 999 999 999 999 999 0 999 999\n999 999 999 999 999 999 999 999 0 999\n999 999 999 999 999 999 999 999 999 0\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003csection\u003e\n\u003c/section\u003e\u003csection\u003e\n \u003cp\u003eNote that she may not need to change any digit.\u003c/p\u003e\n\u003c/section\u003e"}},{"title":"Sample 3","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\u003e3 5\n0 4 3 6 2 7 2 5 3 3\n4 0 5 3 7 5 3 7 2 7\n5 7 0 7 2 9 3 2 9 1\n3 6 2 0 2 4 6 4 2 3\n3 5 7 4 0 6 9 7 6 7\n9 8 5 2 2 0 4 7 6 5\n5 4 6 3 2 3 0 5 4 3\n3 6 2 3 4 2 4 0 8 9\n4 6 5 4 3 5 3 2 0 8\n2 1 3 4 5 7 8 6 4 0\n3 5 2 6 1\n2 5 3 2 1\n6 9 2 5 6\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e47\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003csection\u003e\n\u003c/section\u003e\u003csection\u003e\n\u003c/section\u003e"}}]}