<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>소민's Blog</title>
    <link>https://yygs321.tistory.com/</link>
    <description></description>
    <language>ko</language>
    <pubDate>Tue, 12 May 2026 15:38:35 +0900</pubDate>
    <generator>TISTORY</generator>
    <ttl>100</ttl>
    <managingEditor>박소민</managingEditor>
    <image>
      <title>소민's Blog</title>
      <url>https://tistory1.daumcdn.net/tistory/5123390/attach/92beefaba85a4b82a9c28d6a9d10db3f</url>
      <link>https://yygs321.tistory.com</link>
    </image>
    <item>
      <title>[백준][DP][카데인 알고리즘] 연속합</title>
      <link>https://yygs321.tistory.com/721</link>
      <description>&lt;blockquote data-ke-style=&quot;style2&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;&lt;a title=&quot;https://www.acmicpc.net/problem/1912&quot; href=&quot;https://www.acmicpc.net/problem/1912&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;연속합&lt;/a&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;첫 풀이&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;오류 원인&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;if&amp;nbsp;i&amp;nbsp;==&amp;nbsp;0:&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dp[i]&amp;nbsp;=&amp;nbsp;max(0,&amp;nbsp;numbers[i])&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;-5 -2 -3 일때 max(dp)에서 dp[0]=0 이 채택되면 없는 값이 선택 되는 것&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre id=&quot;code_1771502611183&quot; class=&quot;python&quot; data-ke-language=&quot;python&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;n = int(input())
numbers = list(map(int, input().split()))
dp = numbers[:]
for i in range(n):
    if i == 0:
        dp[i] = max(0, numbers[i])
        continue
    dp[i] = max(numbers[i], dp[i-1]+numbers[i])

print(max(dp))&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;내 풀이&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;해당 위치값부터 시작하거나&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;이전값에서 해당위치값을 더하거나&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;2가지 경우 중 선택&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre id=&quot;code_1771502668537&quot; class=&quot;python&quot; data-ke-language=&quot;python&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;n = int(input())
numbers = list(map(int, input().split()))
dp = numbers[:]
for i in range(1, n):
    dp[i] = max(numbers[i], dp[i-1]+numbers[i])

print(max(dp))&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>코딩테스트/BOJ</category>
      <category>DP</category>
      <category>카데인</category>
      <author>박소민</author>
      <guid isPermaLink="true">https://yygs321.tistory.com/721</guid>
      <comments>https://yygs321.tistory.com/721#entry721comment</comments>
      <pubDate>Thu, 19 Feb 2026 21:07:04 +0900</pubDate>
    </item>
    <item>
      <title>[백준][DP] RGB 거리</title>
      <link>https://yygs321.tistory.com/719</link>
      <description>&lt;blockquote data-ke-style=&quot;style2&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;&lt;a title=&quot;RGB거리&quot; href=&quot;https://www.acmicpc.net/problem/1149&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;RGB거리&lt;/a&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;각 col, row가 어떤 값인지 주의해서 넣을 것&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre id=&quot;code_1771229698602&quot; class=&quot;python&quot; data-ke-language=&quot;python&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;n = int(input())
graph = [list(map(int, input().split())) for _ in range(n)]
dp = [[float('inf') for _ in range(3)] for _ in range(n)]

for i in range(n):
    for j in range(3):
        if i == 0:
            dp[i][j] = graph[i][j]
            continue
        for k in range(3):
            if j == k:
                continue
            dp[i][j] = min(dp[i][j], dp[i-1][k]+graph[i][j])

print(min(dp[n-1]))&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>코딩테스트/BOJ</category>
      <category>DP</category>
      <author>박소민</author>
      <guid isPermaLink="true">https://yygs321.tistory.com/719</guid>
      <comments>https://yygs321.tistory.com/719#entry719comment</comments>
      <pubDate>Mon, 16 Feb 2026 17:15:27 +0900</pubDate>
    </item>
    <item>
      <title>[백준][DP] 설탕 배달﻿</title>
      <link>https://yygs321.tistory.com/718</link>
      <description>&lt;blockquote data-ke-style=&quot;style2&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;&lt;a title=&quot;설탕 배달&quot; href=&quot;https://www.acmicpc.net/problem/2839&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;설탕 배달&lt;/a&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;초기화할때 n이 초기화하는 값보다 작은 경우를 고려해줘야함&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre id=&quot;code_1771228042552&quot; class=&quot;python&quot; data-ke-language=&quot;python&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;n=int(input())
dp=[float('inf') for _ in range(n+1)]
if n&amp;gt;=3:
    dp[3]=1
if n&amp;gt;=5:
    dp[5]=1

for i in range(5, n+1):
    dp[i]=min(dp[i],min(dp[i-3],dp[i-5])+1)

if dp[n]==float('inf'):
    print(-1)
else:
    print(dp[n])&lt;/code&gt;&lt;/pre&gt;</description>
      <category>코딩테스트/BOJ</category>
      <category>DP</category>
      <author>박소민</author>
      <guid isPermaLink="true">https://yygs321.tistory.com/718</guid>
      <comments>https://yygs321.tistory.com/718#entry718comment</comments>
      <pubDate>Mon, 16 Feb 2026 16:48:41 +0900</pubDate>
    </item>
    <item>
      <title>[프로그래머스][그리디] 큰 수 만들기</title>
      <link>https://yygs321.tistory.com/717</link>
      <description>&lt;p data-ke-size=&quot;size16&quot; style=&quot;text-align: left;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/p&gt;&lt;blockquote data-ke-style=&quot;style2&quot;&gt;&lt;a href=&quot;https://school.programmers.co.kr/learn/courses/30/lessons/42883&quot; target=&quot;_blank&quot;&gt;&lt;span&gt;[프로그래머스][그리디] 큰 수 만들기&lt;/span&gt;&lt;/a&gt;&lt;/blockquote&gt;&lt;p data-ke-size=&quot;size16&quot; style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;pre data-ke-type=&quot;codeblock&quot; class=&quot;Python&quot; data-ke-language=&quot;Python&quot;&gt;&lt;code&gt;
def solution(number, k):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;answer = []
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for num in number:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while answer and k&amp;gt;0 and answer[-1]&amp;lt;num:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;answer.pop()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;k-=1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;answer.append(num)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if k&amp;gt;0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;answer=answer[:-k]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return ''.join(answer)&lt;/code&gt;&lt;/pre&gt;&lt;p data-ke-size=&quot;size16&quot; style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt;풀이&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt;1. 숫자를 왼쪽부터 순차적으로 탐색하며 스택에 쌓는다.&lt;/span&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt;2. 새로운 숫자를 넣을 때, 스택에 나보다 작은 숫자가 있다면 그 숫자를 제거하고(k 감소) 내가 그 자리를 대신한다.&lt;/span&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt;3. 반복: 나보다 큰 숫자를 만나거나 k가 0이 될 때까지 앞의 숫자들을 연쇄적으로 지운다.&lt;/span&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt;4. 예외: 전체 탐색 후에도 k가 남았다면, 뒤에서부터 남은 k만큼 잘라낸다 (이미 내림차순인 경우).&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt;시간 복잡도: O(n)인 이유&lt;/span&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt;• 분할 상환 분석(Amortized Analysis)&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt; : for문 안에 while문이 있어 O(n^2)처럼 보일 수 있으나, &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt; 모든 숫자는 스택에 딱 한 번 들어가고(Push), 최대 한 번 나간다(Pop).&lt;/span&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt;• -&amp;gt; 전체 연산 횟수는 최대 2n을 넘지 않음&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt; O(n^2) 이러면 매번 전체를 돌아야함&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt; 하지만 이 로직은 앞에서 제거하면 다시 돌지 않음&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: Nanum Gothic;&quot;&gt; 각 값은 들어오고/나가고 2번의기회뿐 -&amp;gt; O(2n)&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p data-ke-size=&quot;size16&quot; style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;&lt;li&gt;&lt;/li&gt;&lt;/ul&gt;</description>
      <category>코딩테스트/프로그래머스</category>
      <category>그리디</category>
      <category>코테</category>
      <author>박소민</author>
      <guid isPermaLink="true">https://yygs321.tistory.com/717</guid>
      <comments>https://yygs321.tistory.com/717#entry717comment</comments>
      <pubDate>Tue, 10 Feb 2026 00:01:51 +0900</pubDate>
    </item>
    <item>
      <title>[프로그래머스] 가장 가까운 같은 글자</title>
      <link>https://yygs321.tistory.com/716</link>
      <description>&lt;blockquote data-ke-style=&quot;style2&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;&lt;a title=&quot;가장 가까운 같은 글자&quot; href=&quot;https://school.programmers.co.kr/learn/courses/30/lessons/142086?language=python3&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;가장 가까운 같은 글자&lt;/a&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;figure id=&quot;og_1768917886409&quot; contenteditable=&quot;false&quot; data-ke-type=&quot;opengraph&quot; data-ke-align=&quot;alignCenter&quot; data-og-type=&quot;website&quot; data-og-title=&quot;프로그래머스&quot; data-og-description=&quot;SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프&quot; data-og-host=&quot;programmers.co.kr&quot; data-og-source-url=&quot;https://school.programmers.co.kr/learn/courses/30/lessons/142086?language=python3&quot; data-og-url=&quot;https://programmers.co.kr/&quot; data-og-image=&quot;https://scrap.kakaocdn.net/dn/LU7Tr/dJMb86OVKA5/fMF6pg9WjllzOFbx6FOdQ1/img.png?width=1920&amp;amp;height=960&amp;amp;face=0_0_1920_960,https://scrap.kakaocdn.net/dn/bBM08S/dJMb8862SVq/IjKv0t8BtiMPptb1DHgfs1/img.png?width=1920&amp;amp;height=960&amp;amp;face=0_0_1920_960&quot;&gt;&lt;a href=&quot;https://school.programmers.co.kr/learn/courses/30/lessons/142086?language=python3&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; data-source-url=&quot;https://school.programmers.co.kr/learn/courses/30/lessons/142086?language=python3&quot;&gt;
&lt;div class=&quot;og-image&quot; style=&quot;background-image: url('https://scrap.kakaocdn.net/dn/LU7Tr/dJMb86OVKA5/fMF6pg9WjllzOFbx6FOdQ1/img.png?width=1920&amp;amp;height=960&amp;amp;face=0_0_1920_960,https://scrap.kakaocdn.net/dn/bBM08S/dJMb8862SVq/IjKv0t8BtiMPptb1DHgfs1/img.png?width=1920&amp;amp;height=960&amp;amp;face=0_0_1920_960');&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;og-text&quot;&gt;
&lt;p class=&quot;og-title&quot; data-ke-size=&quot;size16&quot;&gt;프로그래머스&lt;/p&gt;
&lt;p class=&quot;og-desc&quot; data-ke-size=&quot;size16&quot;&gt;SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프&lt;/p&gt;
&lt;p class=&quot;og-host&quot; data-ke-size=&quot;size16&quot;&gt;programmers.co.kr&lt;/p&gt;
&lt;/div&gt;
&lt;/a&gt;&lt;/figure&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;내 풀이&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt; 주의할 점&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;reverse.index(a)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;a가 index를 시도하려는 리스트안에 없으면 &lt;b&gt;ValueError&lt;/b&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;발생&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;a가 있는지 검토 후 진행&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre id=&quot;code_1768917895497&quot; class=&quot;python&quot; data-ke-language=&quot;python&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;def solution(s):
    answer = []
    for idx, a in enumerate(s):
        reverse = list(reversed(s[:idx]))
        if a in reverse:
            i = reverse.index(a)
            answer.append(i + 1)
        else:
            answer.append(-1)
    return answer&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>코딩테스트/프로그래머스</category>
      <author>박소민</author>
      <guid isPermaLink="true">https://yygs321.tistory.com/716</guid>
      <comments>https://yygs321.tistory.com/716#entry716comment</comments>
      <pubDate>Tue, 20 Jan 2026 23:06:32 +0900</pubDate>
    </item>
    <item>
      <title>[프로그래머스][구현] 서버 증설 횟수</title>
      <link>https://yygs321.tistory.com/713</link>
      <description>&lt;blockquote data-ke-style=&quot;style2&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;&lt;a title=&quot;서버 증설 횟수&quot; href=&quot;https://school.programmers.co.kr/learn/courses/30/lessons/389479?language=python3&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;서버 증설 횟수 &lt;/a&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;figure id=&quot;og_1759490180861&quot; contenteditable=&quot;false&quot; data-ke-type=&quot;opengraph&quot; data-ke-align=&quot;alignCenter&quot; data-og-type=&quot;website&quot; data-og-title=&quot;프로그래머스&quot; data-og-description=&quot;SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프&quot; data-og-host=&quot;programmers.co.kr&quot; data-og-source-url=&quot;https://school.programmers.co.kr/learn/courses/30/lessons/389479?language=python3&quot; data-og-url=&quot;https://programmers.co.kr/&quot; data-og-image=&quot;https://scrap.kakaocdn.net/dn/smFZ1/hyZKv6Iyov/Lew2PjG8hWMmFUaUpT8uTk/img.png?width=1920&amp;amp;height=960&amp;amp;face=0_0_1920_960,https://scrap.kakaocdn.net/dn/genup/hyZKxXLWCD/GTSKhyMDcP2K1YUbAfa5A0/img.png?width=1920&amp;amp;height=960&amp;amp;face=0_0_1920_960&quot;&gt;&lt;a href=&quot;https://school.programmers.co.kr/learn/courses/30/lessons/389479?language=python3&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; data-source-url=&quot;https://school.programmers.co.kr/learn/courses/30/lessons/389479?language=python3&quot;&gt;
&lt;div class=&quot;og-image&quot; style=&quot;background-image: url('https://scrap.kakaocdn.net/dn/smFZ1/hyZKv6Iyov/Lew2PjG8hWMmFUaUpT8uTk/img.png?width=1920&amp;amp;height=960&amp;amp;face=0_0_1920_960,https://scrap.kakaocdn.net/dn/genup/hyZKxXLWCD/GTSKhyMDcP2K1YUbAfa5A0/img.png?width=1920&amp;amp;height=960&amp;amp;face=0_0_1920_960');&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;og-text&quot;&gt;
&lt;p class=&quot;og-title&quot; data-ke-size=&quot;size16&quot;&gt;프로그래머스&lt;/p&gt;
&lt;p class=&quot;og-desc&quot; data-ke-size=&quot;size16&quot;&gt;SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프&lt;/p&gt;
&lt;p class=&quot;og-host&quot; data-ke-size=&quot;size16&quot;&gt;programmers.co.kr&lt;/p&gt;
&lt;/div&gt;
&lt;/a&gt;&lt;/figure&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;내 풀이&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;이미 서버 1개가 돌고 있으므로 3명 부터 &amp;rarr; 1개 추가 증설&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;해당 인원을 위해 필요한 서버 수 : need (기본 1개 제외하고)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;현재 이용가능한 서버 수 = len(servers)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;현재 추가로 증설해야 하는 서버 수: plus&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;&amp;nbsp; 주의&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;0~1 시 &amp;rarr; idx =0&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;10~15시 사용가능한 서버 &amp;rarr; idx=14 (14~15시) 까지만 이용 가능&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;그러므로 bisect으로 같은 값까지 포함해서 자르게 하려면 servers에 idx값에 맞춰 넣어줘야함&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;=&amp;gt; idx+k-1 (10+5-1 =14)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre id=&quot;code_1759490476766&quot; class=&quot;python&quot; data-ke-language=&quot;python&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;from bisect import bisect_left

def solution(players, m, k):
    answer=0
    servers=[]
    
    for idx, player in enumerate(players):
        i=bisect_left(servers, idx)
        if i!=0:
            servers=servers[i:]
        
        if player&amp;lt;m:
            continue
            
        need=player//m
        if need&amp;gt;len(servers):
            plus=need-len(servers)
            answer+=plus 
            servers+=[idx+k-1 for _ in range(plus)]
        
    return answer&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>코딩테스트/프로그래머스</category>
      <category>구현</category>
      <author>박소민</author>
      <guid isPermaLink="true">https://yygs321.tistory.com/713</guid>
      <comments>https://yygs321.tistory.com/713#entry713comment</comments>
      <pubDate>Fri, 3 Oct 2025 20:21:32 +0900</pubDate>
    </item>
    <item>
      <title>[백준][이분탐색] 1654.랜선 자르기</title>
      <link>https://yygs321.tistory.com/712</link>
      <description>&lt;blockquote data-ke-style=&quot;style2&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;&lt;a title=&quot;1654.랜선 자르기&quot; href=&quot;https://www.acmicpc.net/problem/1654&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;1654.랜선 자르기&lt;/a&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;내 풀이&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;랜선 길이를 mid로 잡고&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;만들어질 수 있는 갯수 체크&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;필요한 n개보다 많거나 같으면 -&amp;gt; 현재 랜선 길이 mid가 너무 짧은 것&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;max값으로 저장 후&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;l= mid+1&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;필요한 갯수보다 적으면 -&amp;gt; 현재 랜선길이 mid가 너무 긴 것&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;r=mid-1&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt; 주의&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;처음 랜선길이 l=0 으로 잡으면 zeroDivizonError 날 수 있음&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;l=1 로 잡아야함&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre id=&quot;code_1758814328177&quot; class=&quot;python&quot; data-ke-language=&quot;python&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;k, n = map(int, input().split())
lans = [int(input()) for _ in range(k)]

l = 0
r = max(lans)

ans = 0
while l &amp;lt;= r:
    mid = (l+r)//2

    cnt = 0
    for lan in lans:
        cnt += (lan//mid)

    if cnt &amp;gt;= n:
        ans = max(ans, mid)
        l = mid+1
    else:
        r = mid-1

print(ans)&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>코딩테스트/BOJ</category>
      <category>이분탐색</category>
      <author>박소민</author>
      <guid isPermaLink="true">https://yygs321.tistory.com/712</guid>
      <comments>https://yygs321.tistory.com/712#entry712comment</comments>
      <pubDate>Fri, 26 Sep 2025 00:32:24 +0900</pubDate>
    </item>
    <item>
      <title>[백준][다익스트라] 1753. 최단 경로</title>
      <link>https://yygs321.tistory.com/711</link>
      <description>&lt;blockquote data-ke-style=&quot;style2&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;&lt;a title=&quot;1753. 최단 경로&quot; href=&quot;https://www.acmicpc.net/problem/1753&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;1753. 최단 경로&lt;/a&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;내 풀이&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;양수의 가중치를 가지는 방향 그래프 -&amp;gt; 다익스트라&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre id=&quot;code_1758812706144&quot; class=&quot;python&quot; data-ke-language=&quot;python&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;from collections import deque, defaultdict
import heapq

v, e = map(int, input().split())
point = int(input())
graph = defaultdict(list)

for _ in range(e):
    start, end, val = map(int, input().split())
    graph[start].append((end, val))

dist = [float('inf') for _ in range(v+1)]

def dijkstra(start):
    queue = []
    heapq.heappush(queue, (0, start))
    dist[start] = 0

    while queue:
        cur_dist, cur = heapq.heappop(queue)

        for nxt, val in graph[cur]:
            if dist[nxt] &amp;lt;= dist[cur]+val:
                continue
            dist[nxt] = dist[cur]+val
            heapq.heappush(queue, (dist[nxt], nxt))


dijkstra(point)
for d in dist[1:]: #첫번째는 0이므로 제외
    if d == float('inf'):
        print(&quot;INF&quot;)
    else:
        print(d)&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;가장 기본 구조&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre id=&quot;code_1758812761145&quot; class=&quot;python&quot; data-ke-language=&quot;python&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;import heapq

v, e = map(int, input().split())
point = int(input())

graph = [[] for _ in range(v+1)]  # 1번~v번 노드 사용

for _ in range(e):
    start, end, val = map(int, input().split())
    graph[start].append((end, val))

dist = [float('inf')] * (v+1)
dist[point] = 0

queue = []
heapq.heappush(queue, (0, point))

while queue:
    cur_dist, cur = heapq.heappop(queue)
    
    # 이미 더 짧은 거리로 처리한 경우 무시
    if cur_dist &amp;gt; dist[cur]:
        continue

    for nxt, val in graph[cur]:
        if dist[nxt] &amp;gt; dist[cur] + val:
            dist[nxt] = dist[cur] + val
            heapq.heappush(queue, (dist[nxt], nxt))

for d in dist[1:]:
    print(&quot;INF&quot; if d == float('inf') else d)&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>코딩테스트/BOJ</category>
      <category>bfs</category>
      <category>다익스트라</category>
      <author>박소민</author>
      <guid isPermaLink="true">https://yygs321.tistory.com/711</guid>
      <comments>https://yygs321.tistory.com/711#entry711comment</comments>
      <pubDate>Fri, 26 Sep 2025 00:06:11 +0900</pubDate>
    </item>
    <item>
      <title>[프로그래머스][Set][교집합]  비밀 코드 해독</title>
      <link>https://yygs321.tistory.com/710</link>
      <description>&lt;blockquote data-ke-style=&quot;style2&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;&lt;a title=&quot;비밀 코드 해독&quot; href=&quot;https://school.programmers.co.kr/learn/courses/30/lessons/388352&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;비밀 코드 해독&lt;/a&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;figure id=&quot;og_1758715178728&quot; contenteditable=&quot;false&quot; data-ke-type=&quot;opengraph&quot; data-ke-align=&quot;alignCenter&quot; data-og-type=&quot;website&quot; data-og-title=&quot;프로그래머스&quot; data-og-description=&quot;SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프&quot; data-og-host=&quot;programmers.co.kr&quot; data-og-source-url=&quot;https://school.programmers.co.kr/learn/courses/30/lessons/388352&quot; data-og-url=&quot;https://programmers.co.kr/&quot; data-og-image=&quot;https://scrap.kakaocdn.net/dn/cxI2ad/hyZJ2CZ9S9/kk3Yoz8AOOsDsjdWxzfxO1/img.png?width=1920&amp;amp;height=960&amp;amp;face=0_0_1920_960,https://scrap.kakaocdn.net/dn/cDwfDw/hyZJkLZ3oI/kbmHCdqtM8BgqGdx9iuI6k/img.png?width=1920&amp;amp;height=960&amp;amp;face=0_0_1920_960&quot;&gt;&lt;a href=&quot;https://school.programmers.co.kr/learn/courses/30/lessons/388352&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; data-source-url=&quot;https://school.programmers.co.kr/learn/courses/30/lessons/388352&quot;&gt;
&lt;div class=&quot;og-image&quot; style=&quot;background-image: url('https://scrap.kakaocdn.net/dn/cxI2ad/hyZJ2CZ9S9/kk3Yoz8AOOsDsjdWxzfxO1/img.png?width=1920&amp;amp;height=960&amp;amp;face=0_0_1920_960,https://scrap.kakaocdn.net/dn/cDwfDw/hyZJkLZ3oI/kbmHCdqtM8BgqGdx9iuI6k/img.png?width=1920&amp;amp;height=960&amp;amp;face=0_0_1920_960');&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;og-text&quot;&gt;
&lt;p class=&quot;og-title&quot; data-ke-size=&quot;size16&quot;&gt;프로그래머스&lt;/p&gt;
&lt;p class=&quot;og-desc&quot; data-ke-size=&quot;size16&quot;&gt;SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프&lt;/p&gt;
&lt;p class=&quot;og-host&quot; data-ke-size=&quot;size16&quot;&gt;programmers.co.kr&lt;/p&gt;
&lt;/div&gt;
&lt;/a&gt;&lt;/figure&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;풀이&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li style=&quot;list-style-type: inherit; color: #000000;&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;제한&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li style=&quot;list-style-type: inherit; color: #000000;&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;10 &amp;le;&amp;nbsp;n&amp;nbsp;&amp;le; 30&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;list-style-type: inherit; color: #000000;&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;1 &amp;le; (q의 길이 =&amp;nbsp;m) &amp;le; 10&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li style=&quot;list-style-type: inherit; color: #000000;&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;30까지의 숫자 중 5개를 고르는 조합 하나씩 돌면서&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;list-style-type: inherit; color: #000000;&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;모든 쿼리랑 교집합 했을때의 갯수가 ans 랑 동일해야함&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li style=&quot;list-style-type: inherit; color: #000000;&quot;&gt;&lt;span style=&quot;color: #000000; text-align: left; font-family: 'Nanum Gothic';&quot;&gt;시간복잡도&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li style=&quot;list-style-type: inherit; color: #000000;&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;30C5 := (24300000 / 120) =202500&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;list-style-type: inherit; color: #000000;&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;q 최대 10&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;list-style-type: inherit; color: #000000;&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;교집합 5&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;list-style-type: inherit; color: #000000;&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;= 202500 * 10 * 5&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li style=&quot;list-style-type: inherit; color: #000000;&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;교집합 갯수가 다르면 out&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre id=&quot;code_1758715513324&quot; class=&quot;python&quot; data-ke-language=&quot;python&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;from itertools import combinations

def solution(n, q, ans):
    answer = 0
    
    for comb in combinations(range(1,n+1),5):
        for i, query in enumerate(q):
            if len(set(comb)&amp;amp;set(query))!=ans[i]:
                break
        else:
             answer+=1  
                
    return answer&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>코딩테스트/프로그래머스</category>
      <category>set</category>
      <category>교집합</category>
      <author>박소민</author>
      <guid isPermaLink="true">https://yygs321.tistory.com/710</guid>
      <comments>https://yygs321.tistory.com/710#entry710comment</comments>
      <pubDate>Wed, 24 Sep 2025 21:06:15 +0900</pubDate>
    </item>
    <item>
      <title>[백준][DP] 2839. 설탕 배달</title>
      <link>https://yygs321.tistory.com/709</link>
      <description>&lt;blockquote data-ke-style=&quot;style2&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;&lt;a title=&quot;2839. 설탕 배달&quot; href=&quot;https://www.acmicpc.net/problem/2839&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;2839. 설탕 배달&lt;/a&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;내 풀이&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li data-end=&quot;226&quot; data-start=&quot;187&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;dp[i] = i kg을 만들 때 필요한 최소 봉지 수.&lt;/span&gt;&lt;/li&gt;
&lt;li data-end=&quot;263&quot; data-start=&quot;230&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;기본값: dp[3] = 1, dp[5] = 1&lt;/span&gt;&lt;/li&gt;
&lt;li data-end=&quot;263&quot; data-start=&quot;230&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;&lt;b&gt;점화식 구현 방식&lt;/b&gt;&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li data-end=&quot;263&quot; data-start=&quot;230&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;i-3, i-5 둘 다 불가능(=0) &amp;rarr; dp[i]도 불가능(=0)&lt;/span&gt;&lt;/li&gt;
&lt;li data-end=&quot;263&quot; data-start=&quot;230&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;두 값이 다 가능하면 &amp;rarr; dp[i] = min(dp[i-3], dp[i-5]) + 1&lt;/span&gt;&lt;/li&gt;
&lt;li data-end=&quot;263&quot; data-start=&quot;230&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;한쪽만 가능하면 &amp;rarr; 그쪽 값 + 1&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li data-end=&quot;263&quot; data-start=&quot;230&quot;&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;즉, &lt;span style=&quot;background-color: #f6e199;&quot;&gt;&lt;b&gt;불가능한 값(0)은 min 비교에 넣으면 안 됨&lt;/b&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre id=&quot;code_1758546631850&quot; class=&quot;python&quot; data-ke-language=&quot;python&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;n = int(input())
dp = [0 for _ in range(max(6, n+1))]
dp[3] = 1
dp[5] = 1
for i in range(6, n+1):
    if dp[i-3] == 0 and dp[i-5] == 0:
        continue
    if dp[i-3] != 0 and dp[i-5] != 0:
        dp[i] = min(dp[i-3], dp[i-5])+1
        continue
    if dp[i-3] == 0:
        dp[i] = dp[i-5]+1
    elif dp[i-5] == 0:
        dp[i] = dp[i-3]+1

print(dp[n] if dp[n] != 0 else -1)&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;다른 사람 풀이&lt;/span&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;5로 나뉘는게 무조건 최소 봉지&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 'Nanum Gothic';&quot;&gt;5로 안되면 모두 3kg 봉지라는 가정하에 &lt;span style=&quot;background-color: #f6e199;&quot;&gt;&lt;b&gt;sugar-=3, bag+=1&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre id=&quot;code_1758546794807&quot; class=&quot;python&quot; data-ke-language=&quot;python&quot; data-ke-type=&quot;codeblock&quot;&gt;&lt;code&gt;sugar = int(input())

bag = 0
while sugar &amp;gt;= 0 :
    if sugar % 5 == 0 :  # 5의 배수이면
        bag += (sugar // 5)  # 5로 나눈 몫을 구해야 정수가 됨
        print(bag)
        break
    sugar -= 3  
    bag += 1  # 5의 배수가 될 때까지 설탕-3, 봉지+1
else :
    print(-1)&lt;/code&gt;&lt;/pre&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>코딩테스트/BOJ</category>
      <category>DP</category>
      <author>박소민</author>
      <guid isPermaLink="true">https://yygs321.tistory.com/709</guid>
      <comments>https://yygs321.tistory.com/709#entry709comment</comments>
      <pubDate>Mon, 22 Sep 2025 22:17:55 +0900</pubDate>
    </item>
  </channel>
</rss>