[백준 11053] 다이나믹 프로그래밍 - 가장 긴 증가하는 부분 수열

김민지·2023년 3월 20일
0

냅다 시작 백준

목록 보기
33/118

✨ 문제 ✨

✨ 정답 ✨

const { json } = require("express/lib/response");
const fs = require("fs");
const filePath = process.platform === "linux" ? "/dev/stdin" : "./예제.txt";
let input = fs.readFileSync(filePath).toString().trim().split('\n');

// const input = require('fs').readFileSync('/dev/stdin').toString().trim().split("\n")


let N = +input[0]
input.shift()
let array = input[0].split(' ').map(el => +el)

dp = [...new Array(N).fill(1)]

for (let i=1;i<N;i++){
  const values=[1];
  for (let j=0;j<i;j++){
    if (array[i]>array[j]){
      values.push(dp[j]+1);
    }
    dp[i]=Math.max(...values);
  }
}
console.log(Math.max(...dp))

//https://nyang-in.tistory.com/275
profile
이건 대체 어떻게 만든 거지?

0개의 댓글