본문 바로가기

Algorithm475

[파이썬] 프로그래머스 : 가장 긴 팰린드롬 (레벨3) [파이썬] 프로그래머스 : 가장 긴 팰린드롬 (레벨3)https://school.programmers.co.kr/learn/courses/30/lessons/12904풀이방향성 생각가장 긴 팰린드롬을 찾는거라 가장 긴 팰린드롬부터 찾아준다.포인터를 이용해서 양 끝 팰린드롬 비교한다. 전체코드def solution(s): L = len(s) for i in range(L,0,-1): # 팰린드롬 길이 for j in range(L-i+1): # 시작 위치 l,r = j,j+i-1 flag = True while l코멘트DP로는 잘 몰?루 2024. 6. 10.
[파이썬] 프로그래머스 : 혼자 놀기의 달인 (레벨2) [파이썬] 프로그래머스 : 혼자 놀기의 달인 (레벨2)https://school.programmers.co.kr/learn/courses/30/lessons/131130풀이방향성 생각그냥 간단한 구현다음 연결 카드를 찾는 과정에서 재귀로 깔끔하게 짤 수도 있을 듯전체코드def solution(cards): # play를 통해서 카드 연결하고 그룹 찾기 def play(x,V): group = [] while not V[x]: V[x] = True group.append(x) x = cards[x]-1 return group L = len(cards) answer = 0 for i i.. 2024. 6. 10.
[파이썬] 백준 12869 : 뮤탈리스크 (골드4) [파이썬] 백준 12869 : 뮤탈리스크 (골드4)https://www.acmicpc.net/problem/12869풀이방향성 생각바텀업보다는 탑다운이 짜기 더 쉬워보인다.전체코드import syssys.setrecursionlimit(10**6)N = int(input())HP = list(map(int,input().split()))for _ in range(3-N): HP.append(0)dp = {}def dfs(a,b,c): # 재방문 if (a,b,c) in dp: return dp[(a,b,c)] # 탈출조건 if (a,b,c) == (0,0,0): return 0 answer = min(dfs(max(a-9,0),max(b-3,0),.. 2024. 6. 8.
[파이썬] 백준 14948 : 군대탈출하기 (골드2) [파이썬] 백준 14948 : 군대탈출하기 (골드)https://www.acmicpc.net/problem/14948풀이방향성 생각전체코드import heapq as hqimport sysinput = lambda : sys.stdin.readline().rstrip()inside = lambda x,y: 0코멘트벽뿌랑 비슷한문제 2024. 6. 8.