백준 알고리즘 풀이 10973번 - 이전 순열
https://www.acmicpc.net/problem/10973 10973번: 이전 순열 첫째 줄에 입력으로 주어진 순열의 이전에 오는 순열을 출력한다. 만약, 사전순으로 가장 처음에 오는 순열인 경우에는 -1을 출력한다. www.acmicpc.net - 순열 문제 알고리즘 1. 뒤에서부터 n[i] > n[i+1]인 i를 찾아서 index에 저장 2. 뒤에서부터 index까지 arr[index] > arr[j]인 j를 찾아서, arr[index]와 arr[j]를 바꾸어준다. 3. index+1부터 수열 끝까지 뒤집어준다. 시간 복잡도 O(N) 소스코드 #include using namespace std; int arr[10001]; int n; int check = false; void reverse..
2021.07.06