AcWing 1017. 怪盗基德的滑翔翼 (javascript)
原题链接
简单
作者:
cp777
,
2021-03-09 10:05:45
,
所有人可见
,
阅读 216
const N = 110;
let g = [];
let f = new Int32Array(N);
let k = 0;
let flag = true;
let n = 0;
let res = 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) {
k = getInputNums(line)[0];
} else if (lineIdx <= k * 2) {
if (flag) {
n = getInputNums(line)[0];
flag = false;
} else {
let arr = getInputNums(line);
g[0] = 0;
for (let i = 1; i <= arr.length; i++) g[i] = arr[i - 1];
// console.log(g[0][2]);
//正序最长子序列
for (let i = 1; i <= n; i++) {
f[i] = 1;
for (let j = 1; j < i; j++) {
if (g[i] > g[j]) {
f[i] = Math.max(f[i], f[j] + 1);
}
}
res = Math.max(res, f[i]);
}
for (let i = 1; i <= n; i++)
//倒序最长子序列
for (let i = n; i >= 1; i--) {
f[i] = 1;
for (let j = n; j > i; j--) {
if (g[i] > g[j]) {
f[i] = Math.max(f[i], f[j] + 1);
}
}
res = Math.max(res, f[i]);
}
console.log(res);
//恢复初始状态
res = 0
flag = true;
g = [];
}
}
});
});