AcWing 1018. 最低通行费 (Javascript)
原题链接
简单
作者:
cp777
,
2021-03-06 17:41:39
,
所有人可见
,
阅读 340
const N = 110;
let f = [];
for (let i = 0; i < N; i++) f[i] = new Int32Array(N).fill(1e8);
let g = [];
g.push('');
let n = 0;
let buf = '';
process.stdin.on('readable', function () {
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
let getInputNums = line => line.split(' ').filter(s => s !== '').map(x => parseInt(x));
let getInputStr = line => line.split(' ').filter(s => s !== '');
process.stdin.on('end', function () {
buf.split('\n').forEach(function (line, lineIdx) {
if (lineIdx === 0) {
n = getInputNums(line)[0];
} else if (lineIdx <= n) {
let arr = getInputNums(line);
arr.unshift(0);
g.push(arr);
if (lineIdx === n) {
f[0][1] = 0;
f[1][0] = 0;
for (let i = 1; i <= n; i++) {
for (let j = 1; j <= n; j++) {
f[i][j] = Math.min(f[i - 1][j] , f[i][j - 1]) + g[i][j];
}
}
console.log(f[n][n]);
}
}
});
});