-
Notifications
You must be signed in to change notification settings - Fork 1
Conversation
characters.sort() | ||
|
||
|
||
def backtracking(length: int, max_idx: int): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
깔끔한 백트래킹 풀이같아요! 변수명이 직관적이어서 이해가 잘 됐습니다~!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
깔끔한 풀이 감사합니다 우열님!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
재귀에서 매개변수가 복잡해지면 풀이가 비교적 단순해지고, 매개변수가 단순해지면 풀이가 비교적 복잡해지는 특성이 있는 것 같다는 걸 느꼈습니다. 둘 중 어떤 것이 맞고 틀리고가 아닌 본인이 편한 것을 선택하면 좋을 것 같아요. 고생하셨습니다!
2. 백 트래킹을 위한 검사문들을 작성한다. | ||
1. 중복을 허용하지 않고 알파벳 사전순일 경우만 확인하기 때문에 현재 담겨있는 알파벳보다 더 큰 인덱스 값만 검사한다. | ||
|
||
2. 방문하지 않은 알파벳일 경우 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
개인적으로 정렬된 리스트를 탐색하거나 순서가 정해진 경우의 백트래킹, 재귀에서는 매개변수를 통해 인덱스를 증가시키는 방향으로 재귀를 수행하는 것을 선호합니다. 그러면 별도의 방문 처리가 필요 없거든요!
characters: List[str] = input().split() | ||
|
||
# 모음의 갯수 | ||
vowels: Set[str] = set(["a", "e", "i", "o", "u"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vowels: Set[str] = {'a', 'e', 'i', 'o', 'u'}
처럼 작성해도 좋을 것 같습니다. 저도 몰랐었는데 PEP8에서 리스트나 셋을 선언할 때 a=set()
이렇게 선언하는 것을 지양하더라구요! set()
이나 list()
키워드는 형변환 할 때에만 사용하고 선언 시에는 braket만 써도 좋을 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zsmalla 오 꿀팁 감사합니다 지수님!
PR Summary
암호 만들기
https://www.acmicpc.net/problem/1759
풀이시간
10:52 ~ 11:43 (49분)
문제 조건
3 <= L <= C <= 15
L개의 알파벳 소문자 (최소 한 개의 모음과 두 개의 자음)
시간 복잡도 : O(L x C)
접근법
무슨 알고리즘으로 풀이 할 수 있을까? -> 백 트래킹
백트래킹을 구현하며 Base Condition(길이가 L과 같고 모음의 갯수가 0보다 크고 자음의 갯수가 1보다 클 경우)일 경우만 값을 출력
백 트래킹을 위한 검사문들을 작성한다.
중복을 허용하지 않고 알파벳 사전순일 경우만 확인하기 때문에 현재 담겨있는 알파벳보다 더 큰 인덱스 값만 검사한다.
방문하지 않은 알파벳일 경우
2-1. 현재 위치를 방문 처리하고 해당 값을 Password에 넣은 뒤 자음과 모음 갯수를 업데이트한다.
2-2. 다음 자리 알파벳을 백 트래킹으로 찾는다.
2-3. 탐색된 알파벳을 방문처리를 해제하고 자,모음 갯수를 다시 업데이트 한다.