题目解析
题目假定在数组中最多只存在一个可能的匹配。因此我们只要找到即返回。
JS算法源码
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
const n = parseInt(await readline());
const matrix = [];
for (let i = 0; i < n; i++) {
matrix.push((await readline()).split(","));
}
const word = await readline();
const used = new Array(n).fill(0).map(() => new Array(n).fill(false));
const path = [];
function dfs(i, j, k) {
if (
i < 0 ||
i >= n ||