https://www.acmicpc.net/problem/20986
20986번: Group Photo
At the end of a training camp, a group photo is taken with the N participants.The participants are numbered from 1 to N, in order of height. The height of the participant h is h (1 ≤ h ≤ N). The participants stand on the stairs for the photo. There are
www.acmicpc.net
Tag : dynamic programming, prefix sum
문제요약
수열
이 때 최소 swap 횟수를 구하라.
풀이
관찰이 조금 필요하다.
그래서
따라서 문제의 조건을 만족하는 수열은
여기까지 생각하는 것도 험난하다...
reverse하지 않은
그래서 위의 경우는
첫 관찰을 했다면 위의 점화식까지 도출하는 과정은 어렵지 않다.
중괄호 안의
독특한 정의의 prefix sum을 만들면 이를
이것 때문에 prefix sum태그가 달렸다.
그럼 이제 아래와 같이 문제를 풀 수 있다.
시간복잡도 :

'BOJ' 카테고리의 다른 글
[BOJ 11997] Load Balancing (silver) (0) | 2021.11.21 |
---|---|
[BOJ 23569] Friendship Graph (0) | 2021.11.21 |
[BOJ 17927] Counting Greedily Increasing Supersequences (0) | 2021.11.12 |
[BOJ 16182] Dumae (0) | 2021.08.15 |
[BOJ 17469] 트리의 색깔과 쿼리 (0) | 2021.08.14 |