题解 | #Redraiment的走法#
Redraiment的走法
https://www.nowcoder.com/practice/24e6243b9f0446b081b1d6d32f2aa3aa
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
// 最长单调递增序列
void async function () {
// Write your code here
const n = await readline();
const datas = (await readline()).split(' ').filter(i => i).map(i => parseInt(i));
if (parseInt(n) != datas.length) {
throw new Error('非法输入')
}
const num = maxLong(datas)
console.log(num)
}()
// f(n) = f(i) + 1, i < n
function maxLong(datas) {
let maxLongs = [];
let max = 0;
for (let i = 0; i < datas.length; i++) {
maxLongs[i] = 1;
for (j = 0; j < i; j++) {
if (datas[j] < datas[i]) {
maxLongs[i] = Math.max(maxLongs[j] + 1, maxLongs[i]);
}
}
max = max < maxLongs[i] ? maxLongs[i] : max;
}
return max;
}

