题解 | #合唱队#
合唱队
https://www.nowcoder.com/practice/6d9d69e3898f45169a441632b325c7b4
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); let index = 0 let input =[] rl.on('line', function (line) { index ++ if(index === 2){ solution(line) } }); function solution(line:string){ let nums = line.split(" ").map(x=>Number(x)) let arr1 = getDpArr(nums) let arr2 = getDpArr(nums.slice().reverse()).reverse() let arr3 = arr1.map((x,idx)=>x+arr2[idx]-1) let maxLen = Math.max(...arr3) let minOut = nums.length - maxLen console.log(minOut); } function getDpArr(nums:number[]){ let length = nums.length let dp = Array.from({length}).map(()=>1) for (let index = 0; index < dp.length; index++) { const element = nums[index]; let lens = nums.slice(0,index) .map((x,idx)=>[x,idx]) .filter(([x,idx])=>x<element).map(([x,idx])=>dp[idx]) let len = Math.max(0,...lens) dp[index] = len+1 } return dp }