티스토리 뷰
https://www.acmicpc.net/problem/10819
const [ N, ...nums ] = require('fs').readFileSync('./dev/stdin').toString().trim().split(/\s+/).map(v => +v);
let max = 0;
function diffMax(arr,visited){
if(arr.length==N){
let sum = 0;
for(let i = 0; i<N-1; i++){
sum+=Math.abs(arr[i]-arr[i+1])
}
if(sum>max) max = sum;
return;
}else{
for(let i = 0; i<N; i++){
if(!(visited&(1<<i))){
arr.push(nums[i]);
diffMax(arr,visited|(1<<i));
arr.pop();
}
}
}
}
diffMax([],0);
console.log(max)
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js)백준 14391번: 종이조각 (0) | 2022.01.05 |
---|---|
Node.js)백준 10971번: 외판원 순회 2 (0) | 2022.01.05 |
Node.js)백준 10973번: 이전 순열 (0) | 2022.01.05 |
Node.js)백준 10972번: 다음 순열 (0) | 2022.01.04 |
Node.js) 백준 10974번: 모든 순열 (0) | 2022.01.03 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 다이나밍프로그래밍
- MOD
- 로드나인
- 그래프
- create databases;
- 투포인터 연습
- 다이나믹프로그래밍
- 최소공통조상
- 롱베케이션
- 투포인터
- 서버개발
- 면접질문
- 개발자면접
- 면접비
- DB 생성
- node.js
- create db
- BFS
- 동적프로그래밍
- 서버점검
- MySQL
- 은둔청년체험
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함