<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DP Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/dp/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Mon, 13 Oct 2025 06:07:16 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://lycos7560.com/wp-content/uploads/2022/11/cropped-cropped-cropped-log-1-150x150-1-80x80.png</url>
	<title>DP Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>백준 14003번 (가장 긴 증가하는 부분 수열 5, C++)</title>
		<link>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-14003%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b8%b4-%ec%a6%9d%ea%b0%80%ed%95%98%eb%8a%94-%eb%b6%80%eb%b6%84-%ec%88%98%ec%97%b4-5-c/40314/</link>
					<comments>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-14003%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b8%b4-%ec%a6%9d%ea%b0%80%ed%95%98%eb%8a%94-%eb%b6%80%eb%b6%84-%ec%88%98%ec%97%b4-5-c/40314/#comments</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 13 Oct 2025 06:06:17 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[14003]]></category>
		<category><![CDATA[14003번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Algorithm Analysis]]></category>
		<category><![CDATA[Algorithm Explanation]]></category>
		<category><![CDATA[Algorithm Practice]]></category>
		<category><![CDATA[Algorithm Study]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[Binary Search]]></category>
		<category><![CDATA[Binary Search LIS]]></category>
		<category><![CDATA[binary_search]]></category>
		<category><![CDATA[BOJ 14003]]></category>
		<category><![CDATA[BOJ Solution]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[C++ Algorithm]]></category>
		<category><![CDATA[C++ STL]]></category>
		<category><![CDATA[Coding Interview]]></category>
		<category><![CDATA[Coding Lecture]]></category>
		<category><![CDATA[Coding Test]]></category>
		<category><![CDATA[Competitive Coding]]></category>
		<category><![CDATA[Competitive Programming]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DP Table]]></category>
		<category><![CDATA[Dynamic Programming]]></category>
		<category><![CDATA[Efficiency]]></category>
		<category><![CDATA[Example Walkthrough]]></category>
		<category><![CDATA[Fast IO]]></category>
		<category><![CDATA[Greedy]]></category>
		<category><![CDATA[Greedy Algorithm]]></category>
		<category><![CDATA[Implementation]]></category>
		<category><![CDATA[Increasing Sequence]]></category>
		<category><![CDATA[Index Mapping]]></category>
		<category><![CDATA[Index Tracking]]></category>
		<category><![CDATA[Input Output]]></category>
		<category><![CDATA[LIS]]></category>
		<category><![CDATA[LIS Diagram]]></category>
		<category><![CDATA[LIS Example]]></category>
		<category><![CDATA[LIS Flow]]></category>
		<category><![CDATA[LIS Indexing]]></category>
		<category><![CDATA[LIS Pattern]]></category>
		<category><![CDATA[LIS Reconstruction]]></category>
		<category><![CDATA[LIS Reconstruction Algorithm]]></category>
		<category><![CDATA[LIS step by step]]></category>
		<category><![CDATA[LIS Study]]></category>
		<category><![CDATA[LIS Table]]></category>
		<category><![CDATA[LIS Tail]]></category>
		<category><![CDATA[LIS Track]]></category>
		<category><![CDATA[LIS Tutorial]]></category>
		<category><![CDATA[LIS using Binary Search]]></category>
		<category><![CDATA[LIS Visualization]]></category>
		<category><![CDATA[LIS 강의]]></category>
		<category><![CDATA[LIS 구현]]></category>
		<category><![CDATA[LIS 단계별]]></category>
		<category><![CDATA[LIS 문제]]></category>
		<category><![CDATA[LIS 문제풀이]]></category>
		<category><![CDATA[LIS 복원]]></category>
		<category><![CDATA[LIS 복원 알고리즘]]></category>
		<category><![CDATA[LIS 알고리즘]]></category>
		<category><![CDATA[LIS 예제]]></category>
		<category><![CDATA[LIS 추적]]></category>
		<category><![CDATA[LIS 코드]]></category>
		<category><![CDATA[LIS 패턴]]></category>
		<category><![CDATA[Logic Explanation]]></category>
		<category><![CDATA[Longest Increasing Subsequence]]></category>
		<category><![CDATA[Longest Subsequence]]></category>
		<category><![CDATA[lower_bound]]></category>
		<category><![CDATA[Memory Limit]]></category>
		<category><![CDATA[Memory Optimization]]></category>
		<category><![CDATA[O(N log N)]]></category>
		<category><![CDATA[O(N^2)]]></category>
		<category><![CDATA[O(NlogN)]]></category>
		<category><![CDATA[Optimal Algorithm]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Prev Index]]></category>
		<category><![CDATA[Problem Explanation]]></category>
		<category><![CDATA[problem solving]]></category>
		<category><![CDATA[Programming Algorithm]]></category>
		<category><![CDATA[Programming Study]]></category>
		<category><![CDATA[Sequence Analysis]]></category>
		<category><![CDATA[Sequence Optimization]]></category>
		<category><![CDATA[Sequence Problem]]></category>
		<category><![CDATA[Sequence Reconstruction]]></category>
		<category><![CDATA[Sequence Trace]]></category>
		<category><![CDATA[STL]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[Subsequence]]></category>
		<category><![CDATA[Tail Array]]></category>
		<category><![CDATA[Theory]]></category>
		<category><![CDATA[Time Complexity]]></category>
		<category><![CDATA[Time Limit]]></category>
		<category><![CDATA[Traceback]]></category>
		<category><![CDATA[upper_bound]]></category>
		<category><![CDATA[vector]]></category>
		<category><![CDATA[가장 긴 증가하는 부분 수열]]></category>
		<category><![CDATA[가장 긴 증가하는 부분 수열 5]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[동적 계획법]]></category>
		<category><![CDATA[디버깅]]></category>
		<category><![CDATA[로직 해설]]></category>
		<category><![CDATA[메모리 최적화]]></category>
		<category><![CDATA[문제 해설]]></category>
		<category><![CDATA[배열]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 14003]]></category>
		<category><![CDATA[백준 14003번]]></category>
		<category><![CDATA[백준 문제풀이]]></category>
		<category><![CDATA[벡터]]></category>
		<category><![CDATA[수열 문제]]></category>
		<category><![CDATA[수열 분석]]></category>
		<category><![CDATA[수열 추적]]></category>
		<category><![CDATA[시간 복잡도]]></category>
		<category><![CDATA[시간 제한]]></category>
		<category><![CDATA[시간 최적화]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[알고리즘 분석]]></category>
		<category><![CDATA[알고리즘 설명]]></category>
		<category><![CDATA[알고리즘 연습]]></category>
		<category><![CDATA[예제 해설]]></category>
		<category><![CDATA[이론]]></category>
		<category><![CDATA[이분 탐색]]></category>
		<category><![CDATA[인덱스 기반 LIS]]></category>
		<category><![CDATA[입출력]]></category>
		<category><![CDATA[자료구조]]></category>
		<category><![CDATA[증가 수열]]></category>
		<category><![CDATA[최장 부분 수열]]></category>
		<category><![CDATA[최적화]]></category>
		<category><![CDATA[최적화 알고리즘]]></category>
		<category><![CDATA[추적]]></category>
		<category><![CDATA[코딩 강의]]></category>
		<category><![CDATA[코딩 공부]]></category>
		<category><![CDATA[코딩 인터뷰]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[탐욕 알고리즘]]></category>
		<category><![CDATA[효율성]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=40314</guid>

					<description><![CDATA[<p>가장 긴 증가하는 부분 수열 5 https://www.acmicpc.net/problem/14003 시간 제한 메모리 제한 제출 정답 맞힌 사람 정답 비율 3 초 512 MB 45574 15974 11322 34.533% 문제 수열 A가 주어졌을 때, 가장 긴 증가하는&#160;부분&#160;수열을 구하는 프로그램을 작성하시오. 예를 들어, 수열 A = {10, 20, 10, 30, 20, 50} 인 경우에 가장 긴 증가하는 부분&#160;수열은&#160;A = {10,&#160;20, [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-14003%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b8%b4-%ec%a6%9d%ea%b0%80%ed%95%98%eb%8a%94-%eb%b6%80%eb%b6%84-%ec%88%98%ec%97%b4-5-c/40314/">백준 14003번 (가장 긴 증가하는 부분 수열 5, C++)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-87ca5ab3      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#가장-긴-증가하는-부분-수열-5" class="uagb-toc-link__trigger">가장 긴 증가하는 부분 수열 5</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#문제" class="uagb-toc-link__trigger">문제</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#입력" class="uagb-toc-link__trigger">입력</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#출력" class="uagb-toc-link__trigger">출력</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#예제-입력-1" class="uagb-toc-link__trigger">예제 입력 1</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#예제-출력-1" class="uagb-toc-link__trigger">예제 출력 1</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#출처" class="uagb-toc-link__trigger">출처</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#비슷한-문제" class="uagb-toc-link__trigger">비슷한 문제</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#알고리즘-분류" class="uagb-toc-link__trigger">알고리즘 분류</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#1차-시도-로직-그대로-구현" class="uagb-toc-link__trigger">1차 시도 &#8211; 로직 그대로 구현</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#2차-시도-이분-탐색-인덱스-추적을-이용한-lis-복원-on-log-n" class="uagb-toc-link__trigger">2차 시도 &#8211; 이분 탐색 + 인덱스 추적을 이용한 LIS 복원 / O(N log N)</a></ul></ol>					</div>
									</div>
				</div>
			


<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">가장 긴 증가하는 부분 수열 5 <img decoding="async" width="35" height="45" class="wp-image-37909" style="width: 35px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Platinum_5.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Platinum_5.jpg 400w, https://lycos7560.com/wp-content/uploads/2024/03/Platinum_5-234x300.jpg 234w" sizes="(max-width: 35px) 100vw, 35px" /></h2>



<p><a href="https://www.acmicpc.net/problem/14003" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/14003</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>시간 제한</th><th>메모리 제한</th><th>제출</th><th>정답</th><th>맞힌 사람</th><th>정답 비율</th></tr></thead><tbody><tr><td>3 초</td><td>512 MB</td><td>45574</td><td>15974</td><td>11322</td><td>34.533%</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">문제</h3>



<p>수열 A가 주어졌을 때, 가장 긴 증가하는&nbsp;부분&nbsp;수열을 구하는 프로그램을 작성하시오.</p>



<p>예를 들어, 수열 A = {10, 20, 10, 30, 20, 50} 인 경우에 가장 긴 증가하는 부분&nbsp;수열은&nbsp;A = {<strong>10</strong>,&nbsp;<strong>20</strong>, 10,&nbsp;<strong>30</strong>, 20,&nbsp;<strong>50</strong>} 이고, 길이는 4이다.</p>



<div style="height:15px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">입력</h3>



<p>첫째 줄에 수열 A의 크기 N (1 ≤ N ≤ 1,000,000)이 주어진다.</p>



<p>둘째 줄에는 수열 A를 이루고 있는 A<sub>i</sub>가 주어진다. (-1,000,000,000&nbsp;≤ A<sub>i</sub>&nbsp;≤ 1,000,000,000)</p>



<div style="height:15px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">출력</h3>



<p>첫째 줄에 수열 A의 가장 긴 증가하는 부분 수열의 길이를 출력한다.</p>



<p>둘째 줄에는 정답이 될 수 있는 가장 긴 증가하는 부분 수열을 출력한다.</p>



<div style="height:15px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-uagb-container uagb-block-aa78ee06 alignfull uagb-is-root-container"><div class="uagb-container-inner-blocks-wrap">
<div class="wp-block-uagb-container uagb-block-70c24c24">
<h3 class="wp-block-heading">예제 입력 1</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">6
10 20 10 30 20 50</pre>
</div>



<div class="wp-block-uagb-container uagb-block-2c88bb50">
<h3 class="wp-block-heading">예제 출력 1</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4
10 20 30 50</pre>
</div>
</div></div>



<div style="height:15px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">출처</h3>



<ul class="wp-block-list">
<li>문제를 만든 사람: <a href="https://www.acmicpc.net/user/baekjoon">baekjoon</a></li>



<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/harinboy">harinboy</a>, <a href="https://www.acmicpc.net/user/jh05013">jh05013</a>, <a href="https://www.acmicpc.net/user/kkw564">kkw564</a>, <a href="https://www.acmicpc.net/user/ldw0318">ldw0318</a>, <a href="https://www.acmicpc.net/user/minho6428">minho6428</a>, <a href="https://www.acmicpc.net/user/sohnryang">sohnryang</a>, <a href="https://www.acmicpc.net/user/surung9898">surung9898</a>, <a href="https://www.acmicpc.net/user/yeo2507">yeo2507</a></li>



<li>빠진 조건을 찾은 사람: <a href="https://www.acmicpc.net/user/Acka">Acka</a></li>
</ul>



<div style="height:15px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">비슷한 문제</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/11053" target="_blank" rel="noreferrer noopener">11053번. 가장 긴 증가하는 부분 수열</a></li>



<li><a href="https://www.acmicpc.net/problem/11054" target="_blank" rel="noreferrer noopener">11054번. 가장 긴 바이토닉 부분 수열</a></li>



<li><a href="https://www.acmicpc.net/problem/11055" target="_blank" rel="noreferrer noopener">11055번. 가장 큰 증가하는 부분 수열</a></li>



<li><a href="https://www.acmicpc.net/problem/11722" target="_blank" rel="noreferrer noopener">11722번. 가장 긴 감소하는 부분 수열</a></li>



<li><a href="https://www.acmicpc.net/problem/12015" target="_blank" rel="noreferrer noopener">12015번. 가장 긴 증가하는 부분 수열 2</a></li>



<li><a href="https://www.acmicpc.net/problem/12738" target="_blank" rel="noreferrer noopener">12738번. 가장 긴 증가하는 부분 수열 3</a></li>



<li><a href="https://www.acmicpc.net/problem/14002" target="_blank" rel="noreferrer noopener">14002번. 가장 긴 증가하는 부분 수열 4</a></li>
</ul>



<div style="height:15px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">알고리즘 분류</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/12" target="_blank" rel="noreferrer noopener">이분 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/235" target="_blank" rel="noreferrer noopener">역추적</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/43" target="_blank" rel="noreferrer noopener">가장 긴 증가하는 부분 수열 문제</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--60);margin-bottom:var(--wp--preset--spacing--60)"/>



<h3 class="wp-block-heading">1차 시도 &#8211; 로직 그대로 구현</h3>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1043" height="115" src="https://lycos7560.com/wp-content/uploads/2025/10/image-4.png" alt="" class="wp-image-40317" srcset="https://lycos7560.com/wp-content/uploads/2025/10/image-4.png 1043w, https://lycos7560.com/wp-content/uploads/2025/10/image-4-300x33.png 300w, https://lycos7560.com/wp-content/uploads/2025/10/image-4-768x85.png 768w" sizes="(max-width: 1043px) 100vw, 1043px" /></figure>



<p>한 번의 입력(<code>num</code>)에 의해 생성된 새로운 시퀀스들을 임시로 저장</p>



<p>어떤 수열에도 붙을 수 없으면 독립된 시퀀스 시작</p>



<p>나중에 불필요한 시퀀스(같은 길이인데 꼬리가 큰 것)는 제거</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;vector>

using namespace std;

int n; // 수열의 개수
vector&lt;vector&lt;int>> Sequences;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n;
    if (n &lt;= 0) return 0;

    int num;
    cin >> num;

    // 첫 번째 수로 초기 시퀀스 하나 생성
    vector&lt;int> sequence;
    sequence.push_back(num);
    Sequences.push_back(sequence);

    for (int i = 1; i &lt; n; i++)
    {
        cin >> num;
        int length = Sequences.size();

        bool canExtend = false;
        vector&lt;vector&lt;int>> newSequences;

        // 기존 시퀀스들을 모두 검사
        for (int j = 0; j &lt; length; j++)
        {
            int last = Sequences[j].back();

            // 확장 가능한 경우 : 새로운 시퀀스 생성
            if (last &lt; num)
            {
                canExtend = true;
                vector&lt;int> extendedSeq = Sequences[j];
                extendedSeq.push_back(num);
                newSequences.push_back(extendedSeq);
            }
        }

        // 어떤 시퀀스에도 붙지 못하면 새로운 시퀀스 시작
        if (!canExtend)
        {
            vector&lt;int> newSeq;
            newSeq.push_back(num);
            newSequences.push_back(newSeq);
        }

        // 새로 생긴 시퀀스들을 기존에 합침
        for (auto&amp; seq : newSequences)
            Sequences.push_back(seq);

        // 최적 시퀀스 길이 및 꼬리값 계산
        int maxSeqSize = 0;
        int bestIndex = 0;
        int bestTail = 1000000001;

        for (int j = 0; j &lt; (int)Sequences.size(); j++)
        {
            int sz = Sequences[j].size();
            int tail = Sequences[j].back();
            if (sz > maxSeqSize || (sz == maxSeqSize &amp;&amp; tail &lt; bestTail))
            {
                maxSeqSize = sz;
                bestTail = tail;
                bestIndex = j;
            }
        }

        // 가지치기: 같은 길이인데 꼬리값이 큰 시퀀스 제거
        for (int j = 0; j &lt; (int)Sequences.size();)
        {
            int sz = Sequences[j].size();
            int tail = Sequences[j].back();

            if (sz == maxSeqSize &amp;&amp; tail > bestTail)
            {
                Sequences.erase(Sequences.begin() + j);
            }
            else
            {
                j++;
            }
        }
    }

	// 결과 중 가장 긴 시퀀스 찾기
    int maxSize = 0;
    int bestIdx = 0;
    for (int i = 0; i &lt; (int)Sequences.size(); i++)
    {
        if (Sequences[i].size() > maxSize)
        {
            maxSize = Sequences[i].size();
            bestIdx = i;
        }
    }

    cout &lt;&lt; maxSize &lt;&lt; "\n";
    for (int x : Sequences[bestIdx])
        cout &lt;&lt; x &lt;&lt; " ";

    return 0;
}
</pre>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<p>브루트포스 방식으로 모든 가능한 증가 수열을 시도하는 방법은 시간 초과 및 메모리 초과로 인하여 통과할 수 없음.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="604" height="509" src="https://lycos7560.com/wp-content/uploads/2025/10/image-3.png" alt="" class="wp-image-40318" srcset="https://lycos7560.com/wp-content/uploads/2025/10/image-3.png 604w, https://lycos7560.com/wp-content/uploads/2025/10/image-3-300x253.png 300w" sizes="(max-width: 604px) 100vw, 604px" /></figure>



<p><strong>매 반복마다</strong> <code>Sequences</code>의 크기가 <strong>기하급수적으로 늘어나는 구조</strong></p>



<p>n개의 원소가 들어오면 2ⁿ에 비례하는 시퀀스로 통과하기 힘들다. (O(2ⁿ))</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>단계</th><th>가능한 Sequences 수</th></tr></thead><tbody><tr><td>1</td><td>[ [1] ]</td></tr><tr><td>2</td><td>[ [1], [2], [1,2] ]</td></tr><tr><td>3</td><td>[ [1], [2], [3], [1,2], [1,3], [2,3], [1,2,3] ]</td></tr><tr><td>4</td><td>거의 모든 가능한 증가 부분 수열이 등장함 (약 15개)</td></tr></tbody></table></figure>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--50);margin-bottom:var(--wp--preset--spacing--50)"/>



<h3 class="wp-block-heading">2차 시도 &#8211; <strong>이분 탐색 + 인덱스 추적</strong>을 이용한 LIS 복원 / O(N log N)</h3>



<figure class="wp-block-image size-full"><img decoding="async" width="1042" height="39" src="https://lycos7560.com/wp-content/uploads/2025/10/image-7.png" alt="" class="wp-image-40322" srcset="https://lycos7560.com/wp-content/uploads/2025/10/image-7.png 1042w, https://lycos7560.com/wp-content/uploads/2025/10/image-7-300x11.png 300w, https://lycos7560.com/wp-content/uploads/2025/10/image-7-768x29.png 768w" sizes="(max-width: 1042px) 100vw, 1042px" /></figure>



<p>최장 증가 수열 (LIS, Longest Increasing Subsequence)</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;vector>
#include &lt;algorithm>

using namespace std;

// (LIS, Longest Increasing Subsequence)

int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    int N;
    std::cin >> N;

    vector&lt;int> input(N);
    for (int i = 0; i &lt; N; i++)
        std::cin >> input[i];

    vector&lt;int> tail;  // LIS를 구성하는 인덱스들
    vector&lt;int> prev_idx(N, -1);  //각 요소가 LIS에 포함될 때, 그 직전 요소의 인덱스를 저장


    for (int i = 0; i &lt; N; i++)
    {
        // 이분 탐색으로 input[i]가 tail 배열에서 들어가야 할 위치 찾기
        int lo = 0;
        int hi = (int)tail.size() - 1;
        int pos = (int)tail.size(); // 기본값은 맨 뒤

        while (lo &lt;= hi)
        {
            int mid = (lo + hi) / 2;
            // input[i]보다 크거나 같은 첫 번째 tail 원소 위치(pos)를 찾
            if (input[tail[mid]] &lt; input[i])
            {
                lo = mid + 1;
            }
            else
            {
                pos = mid;
                hi = mid - 1;
            }
        }

        // 이전 인덱스 설정
        if (pos > 0)
        {
            prev_idx[i] = tail[pos - 1];
        }
        else
        {
            prev_idx[i] = -1;  // 첫 번째 요소
        }

        // tail 업데이트
        if (pos == (int)tail.size())
        {
            tail.push_back(i);
        }
        else
        {
            tail[pos] = i;
        }
    }

    // 결과: LIS 길이
    int lis_len = (int)tail.size();
    std::cout &lt;&lt; lis_len &lt;&lt; "\n";

    // 실제 LIS 수열 재구성
    vector&lt;int> lis;
    for (int idx = tail.back(); idx != -1; idx = prev_idx[idx])
    {
        lis.push_back(input[idx]);
    }
    reverse(lis.begin(), lis.end());

    for (int v : lis)
        std::cout &lt;&lt; v &lt;&lt; " ";
    std::cout &lt;&lt; "\n";

    return 0;
}</pre>



<div style="height:15px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="651" height="324" src="https://lycos7560.com/wp-content/uploads/2025/10/image-5.png" alt="" class="wp-image-40319" srcset="https://lycos7560.com/wp-content/uploads/2025/10/image-5.png 651w, https://lycos7560.com/wp-content/uploads/2025/10/image-5-300x149.png 300w" sizes="(max-width: 651px) 100vw, 651px" /></figure>



<p><code>input[i]</code>가 들어가야 할 위치(<code>pos</code>)를 찾음</p>



<p>즉, <code>tail</code> 배열 내에서 <strong>input[i]보다 작지만 가장 큰 값 다음 위치</strong>를 찾는다.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="513" height="466" src="https://lycos7560.com/wp-content/uploads/2025/10/image-6.png" alt="" class="wp-image-40320" srcset="https://lycos7560.com/wp-content/uploads/2025/10/image-6.png 513w, https://lycos7560.com/wp-content/uploads/2025/10/image-6-300x273.png 300w" sizes="(max-width: 513px) 100vw, 513px" /></figure>



<p><code>prev_idx[i]</code>는 <code>input[i]</code> 바로 앞에 올 LIS 원소의 인덱스입니다.</p>



<p><code>pos > 0</code>이면 → 현재 원소가 &#8220;길이 pos+1&#8243;짜리 LIS의 마지막이 되므로 &#8220;그 바로 이전 원소&#8221;는 <code>tail[pos - 1]</code></p>



<p><code>pos == 0</code>이면 → 수열의 첫 번째 원소이므로 이전이 없음</p>



<p><code>pos == tail.size()</code> → <code>input[i]</code>가 지금 까지의 모든 수보다 크므로 LIS 길이 1 증가</p>



<p>그렇지 않으면 → 기존 LIS 후보 중 &#8220;끝값이 더 큰 것&#8221;을 <code>input[i]</code>로 <strong>치환</strong> (더 작은 끝값 유지)</p>



<h4 class="wp-block-heading">예시 1</h4>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">input = [5, 2, 8, 6, 3, 6, 9, 7]</pre>



<div style="height:15px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-table"><table><thead><tr><th class="has-text-align-left" data-align="left">단계</th><th class="has-text-align-left" data-align="left">i</th><th class="has-text-align-left" data-align="left">input[i]</th><th class="has-text-align-left" data-align="left">tail (인덱스)</th><th class="has-text-align-left" data-align="left">tail (값으로 표현)</th><th class="has-text-align-left" data-align="left">prev_idx</th><th class="has-text-align-left" data-align="left">설명</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left">[0]</td><td class="has-text-align-left" data-align="left">[5]</td><td class="has-text-align-left" data-align="left">[-1, ?, ?, ?, ?, ?, ?, ?]</td><td class="has-text-align-left" data-align="left">첫 번째 원소 → 새로운 LIS 시작</td></tr><tr><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">[1]</td><td class="has-text-align-left" data-align="left">[2]</td><td class="has-text-align-left" data-align="left">[-1, -1, ?, ?, ?, ?, ?, ?]</td><td class="has-text-align-left" data-align="left">2 &lt; 5 → 기존 tail[0] 교체 (더 작은 끝값 유지)</td></tr><tr><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">8</td><td class="has-text-align-left" data-align="left">[1, 2]</td><td class="has-text-align-left" data-align="left">[2, 8]</td><td class="has-text-align-left" data-align="left">[-1, -1, 1, ?, ?, ?, ?, ?]</td><td class="has-text-align-left" data-align="left">8 &gt; 2 → 길이 2짜리 LIS 형성</td></tr><tr><td class="has-text-align-left" data-align="left">3</td><td class="has-text-align-left" data-align="left">3</td><td class="has-text-align-left" data-align="left">6</td><td class="has-text-align-left" data-align="left">[1, 3]</td><td class="has-text-align-left" data-align="left">[2, 6]</td><td class="has-text-align-left" data-align="left">[-1, -1, 1, 1, ?, ?, ?, ?]</td><td class="has-text-align-left" data-align="left">6은 2보다 크지만 8보다 작음 → 8을 6으로 교체</td></tr><tr><td class="has-text-align-left" data-align="left">4</td><td class="has-text-align-left" data-align="left">4</td><td class="has-text-align-left" data-align="left">3</td><td class="has-text-align-left" data-align="left">[1, 4]</td><td class="has-text-align-left" data-align="left">[2, 3]</td><td class="has-text-align-left" data-align="left">[-1, -1, 1, 1, 1, ?, ?, ?]</td><td class="has-text-align-left" data-align="left">3은 2보다 크고 6보다 작음 → 6을 3으로 교체</td></tr><tr><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left">6</td><td class="has-text-align-left" data-align="left">[1, 4, 5]</td><td class="has-text-align-left" data-align="left">[2, 3, 6]</td><td class="has-text-align-left" data-align="left">[-1, -1, 1, 1, 1, 4, ?, ?]</td><td class="has-text-align-left" data-align="left">6은 3보다 크므로 길이 3짜리 LIS 생성</td></tr><tr><td class="has-text-align-left" data-align="left">6</td><td class="has-text-align-left" data-align="left">6</td><td class="has-text-align-left" data-align="left">9</td><td class="has-text-align-left" data-align="left">[1, 4, 5, 6]</td><td class="has-text-align-left" data-align="left">[2, 3, 6, 9]</td><td class="has-text-align-left" data-align="left">[-1, -1, 1, 1, 1, 4, 5, ?]</td><td class="has-text-align-left" data-align="left">9 &gt; 6 → 길이 4짜리 LIS 생성</td></tr><tr><td class="has-text-align-left" data-align="left">7</td><td class="has-text-align-left" data-align="left">7</td><td class="has-text-align-left" data-align="left">7</td><td class="has-text-align-left" data-align="left">[1, 4, 5, 7]</td><td class="has-text-align-left" data-align="left">[2, 3, 6, 7]</td><td class="has-text-align-left" data-align="left">[-1, -1, 1, 1, 1, 4, 5, 5]</td><td class="has-text-align-left" data-align="left">7은 6보다 크지만 9보다 작음 → 9를 7로 교체</td></tr></tbody></table></figure>



<div style="height:15px" aria-hidden="true" class="wp-block-spacer"></div>



<h4 class="wp-block-heading">예시 2</h4>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">이분 탐색을 이용한 LIS 구성 로직

input = [3, 5, 2, 7, 4, 1, 8]

--------------------------------

i=0 (값: 3)
tail: [] (빈 배열)
이분탐색: tail.size() = 0 → while문 스킵
pos = 0 (기본값)

prev_idx[0] = -1 (pos=0이므로)
tail 업데이트: pos == tail.size() → push_back(0)
결과: tail = [0] (값: [3])

--------------------------------

i=1 (값: 5)
tail: [0] (값: [3])
이분탐색:
  lo=0, hi=0, mid=0
  input[tail[0]] = 3 &lt; 5 → lo = mid+1 = 1
  lo=1 > hi=0 → 종료
pos = tail.size() = 1

prev_idx[1] = tail[0] = 0 (5 앞에 3)
tail 업데이트: push_back(1)
결과: tail = [0,1] (값: [3,5])

--------------------------------

i=2 (값: 2)
tail: [0,1] (값: [3,5])
이분탐색:
  lo=0, hi=1, mid=0
  input[tail[0]] = 3 >= 2 → pos=0, hi=-1
  lo=0 > hi=-1 → 종료
pos = 0

prev_idx[2] = -1 (pos=0이므로)
tail 업데이트: tail[0] = 2
결과: tail = [2,1] (값: [2,5])

--------------------------------

i=3 (값: 7)
tail: [2,1] (값: [2,5])
이분탐색:
  lo=0, hi=1, mid=0: input[tail[0]]=2 &lt; 7 → lo=1
  lo=1, hi=1, mid=1: input[tail[1]]=5 &lt; 7 → lo=2
  lo=2 > hi=1 → 종료
pos = tail.size() = 2

prev_idx[3] = tail[1] = 1 (7 앞에 5)
tail 업데이트: push_back(3)
결과: tail = [2,1,3] (값: [2,5,7])

--------------------------------

i=4 (값: 4)
tail: [2,1,3] (값: [2,5,7])
이분탐색:
  lo=0, hi=2, mid=1: input[tail[1]]=5 >= 4 → pos=1, hi=0
  lo=0, hi=0, mid=0: input[tail[0]]=2 &lt; 4 → lo=1
  lo=1 > hi=0 → 종료
pos = 1

prev_idx[4] = tail[0] = 2 (4 앞에 2)
tail 업데이트: tail[1] = 4
결과: tail = [2,4,3] (값: [2,4,7])

--------------------------------

i=5 (값: 1)
tail: [2,4,3] (값: [2,4,7])
이분탐색:
  lo=0, hi=2, mid=1: input[tail[1]]=4 >= 1 → pos=1, hi=0
  lo=0, hi=0, mid=0: input[tail[0]]=2 >= 1 → pos=0, hi=-1
  lo=0 > hi=-1 → 종료
pos = 0

prev_idx[5] = -1
tail 업데이트: tail[0] = 5
결과: tail = [5,4,3] (값: [1,4,7])

--------------------------------

i=6 (값: 8)

tail: [5,4,3] (값: [1,4,7])
이분탐색:
  lo=0, hi=2, mid=1: input[tail[1]]=4 &lt; 8 → lo=2
  lo=2, hi=2, mid=2: input[tail[2]]=7 &lt; 8 → lo=3
  lo=3 > hi=2 → 종료
pos = tail.size() = 3

prev_idx[6] = tail[2] = 3 (8 앞에 7)
tail 업데이트: push_back(6)
결과: tail = [5,4,3,6] (값: [1,4,7,8])

</pre>



<p></p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-14003%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b8%b4-%ec%a6%9d%ea%b0%80%ed%95%98%eb%8a%94-%eb%b6%80%eb%b6%84-%ec%88%98%ec%97%b4-5-c/40314/">백준 14003번 (가장 긴 증가하는 부분 수열 5, C++)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-14003%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b8%b4-%ec%a6%9d%ea%b0%80%ed%95%98%eb%8a%94-%eb%b6%80%eb%b6%84-%ec%88%98%ec%97%b4-5-c/40314/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>백준 11053번 (가장 긴 증가하는 부분 수열, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11053%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b8%b4-%ec%a6%9d%ea%b0%80%ed%95%98%eb%8a%94-%eb%b6%80%eb%b6%84-%ec%88%98%ec%97%b4-c-baekjoon/36512/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11053%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b8%b4-%ec%a6%9d%ea%b0%80%ed%95%98%eb%8a%94-%eb%b6%80%eb%b6%84-%ec%88%98%ec%97%b4-c-baekjoon/36512/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 16 Aug 2023 02:53:36 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[11053]]></category>
		<category><![CDATA[11053번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[Sliver]]></category>
		<category><![CDATA[Sliver2]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[가장 긴 증가하는 부분 수열]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 11053]]></category>
		<category><![CDATA[백준 11053번]]></category>
		<category><![CDATA[실버]]></category>
		<category><![CDATA[실버2]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36512</guid>

					<description><![CDATA[<p>백준 11053번 '가장 긴 증가하는 부분 수열' 문제에 대한 글입니다. DP 알고리즘을 이용하여 해결하였습니다. (This article is about Baekjoon Number 11053 "Longest Increasing Partial Sequence" problem. It was solved using DP algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11053%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b8%b4-%ec%a6%9d%ea%b0%80%ed%95%98%eb%8a%94-%eb%b6%80%eb%b6%84-%ec%88%98%ec%97%b4-c-baekjoon/36512/">백준 11053번 (가장 긴 증가하는 부분 수열, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-43345b7a      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#스티커" class="uagb-toc-link__trigger">스티커</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ul></ol>					</div>
									</div>
				</div>
			


<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">스티커 <img decoding="async" width="30" height="38" class="wp-image-37910" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Sliver_2.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Sliver_2.jpg 400w, https://lycos7560.com/wp-content/uploads/2024/03/Sliver_2-234x300.jpg 234w" sizes="(max-width: 30px) 100vw, 30px" /></h1>



<p><a href="https://www.acmicpc.net/problem/11053" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/11053</a></p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p>수열 A가 주어졌을 때, 가장 긴 증가하는&nbsp;부분&nbsp;수열을 구하는 프로그램을 작성하시오.</p>



<p>예를 들어, 수열 A = {10, 20, 10, 30, 20, 50} 인 경우에 가장 긴 증가하는 부분&nbsp;수열은&nbsp;A = {<strong>10</strong>,&nbsp;<strong>20</strong>, 10,&nbsp;<strong>30</strong>, 20,&nbsp;<strong>50</strong>} 이고, 길이는 4이다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p>첫째 줄에 수열 A의 크기 N (1 ≤ N ≤ 1,000)이 주어진다.</p>



<p>둘째 줄에는 수열 A를 이루고 있는 A<sub>i</sub>가 주어진다. (1 ≤ A<sub>i</sub>&nbsp;≤ 1,000)</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p>첫째 줄에 수열 A의 가장 긴 증가하는 부분 수열의 길이를 출력한다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">6
10 20 10 30 20 50</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4</pre>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">출처</h3>



<ul class="wp-block-list">
<li>문제를 만든 사람:&nbsp;<a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/harinboy" target="_blank" rel="noreferrer noopener">harinboy</a></li>
</ul>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">비슷한 문제</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/11054" target="_blank" rel="noreferrer noopener">11054번. 가장 긴 바이토닉 부분 수열</a></li>



<li><a href="https://www.acmicpc.net/problem/11055" target="_blank" rel="noreferrer noopener">11055번. 가장 큰 증가하는 부분 수열</a></li>



<li><a href="https://www.acmicpc.net/problem/11722" target="_blank" rel="noreferrer noopener">11722번. 가장 긴 감소하는 부분 수열</a></li>



<li><a href="https://www.acmicpc.net/problem/12015" target="_blank" rel="noreferrer noopener">12015번. 가장 긴 증가하는 부분 수열 2</a></li>



<li><a href="https://www.acmicpc.net/problem/12738" target="_blank" rel="noreferrer noopener">12738번. 가장 긴 증가하는 부분 수열 3</a></li>



<li><a href="https://www.acmicpc.net/problem/14002" target="_blank" rel="noreferrer noopener">14002번. 가장 긴 증가하는 부분 수열 4</a></li>



<li><a href="https://www.acmicpc.net/problem/14003" target="_blank" rel="noreferrer noopener">14003번. 가장 긴 증가하는 부분 수열 5</a></li>
</ul>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">알고리즘 분류</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/25" target="_blank" rel="noreferrer noopener">다이나믹 프로그래밍</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="1310" height="1920" src="https://lycos7560.com/wp-content/uploads/2023/08/KakaoTalk_20230816_115045407.jpg" alt="" class="wp-image-36525" style="width:897px;height:1315px" srcset="https://lycos7560.com/wp-content/uploads/2023/08/KakaoTalk_20230816_115045407.jpg 1310w, https://lycos7560.com/wp-content/uploads/2023/08/KakaoTalk_20230816_115045407-205x300.jpg 205w, https://lycos7560.com/wp-content/uploads/2023/08/KakaoTalk_20230816_115045407-768x1126.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/08/KakaoTalk_20230816_115045407-1048x1536.jpg 1048w" sizes="(max-width: 1310px) 100vw, 1310px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading has-large-font-size">통과된 코드</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>

using namespace std;

int _N, _Tables[1000], _DP[1000], _Res = 1;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> _N;
	for (int i = 0; i &lt; _N; i++)
		cin >> _Tables[i];
	_DP[0] = 1;
	for (int i = 1; i &lt; _N; i++) {
		int _t = 1;
		for (int j = i - 1; j >= 0; j--)
			if (_Tables[i] > _Tables[j])
				_t = max(_t, _DP[j] + 1);
		_DP[i] = _t;
	}

	for (int i = 0; i &lt; _N; i++)
		_Res = max(_Res, _DP[i]);
	
	cout &lt;&lt; _Res;
	return 0;
}</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1061" height="84" src="https://lycos7560.com/wp-content/uploads/2023/08/image-11.png" alt="" class="wp-image-36521" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-11.png 1061w, https://lycos7560.com/wp-content/uploads/2023/08/image-11-300x24.png 300w, https://lycos7560.com/wp-content/uploads/2023/08/image-11-768x61.png 768w" sizes="(max-width: 1061px) 100vw, 1061px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-format="autorelaxed"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="4386247858"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11053%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b8%b4-%ec%a6%9d%ea%b0%80%ed%95%98%eb%8a%94-%eb%b6%80%eb%b6%84-%ec%88%98%ec%97%b4-c-baekjoon/36512/">백준 11053번 (가장 긴 증가하는 부분 수열, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11053%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b8%b4-%ec%a6%9d%ea%b0%80%ed%95%98%eb%8a%94-%eb%b6%80%eb%b6%84-%ec%88%98%ec%97%b4-c-baekjoon/36512/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 9465번 (스티커, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9465%eb%b2%88-%ec%8a%a4%ed%8b%b0%ec%bb%a4-c-baekjoon/36495/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9465%eb%b2%88-%ec%8a%a4%ed%8b%b0%ec%bb%a4-c-baekjoon/36495/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 14 Aug 2023 01:50:10 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[9465]]></category>
		<category><![CDATA[9465번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[Sliver]]></category>
		<category><![CDATA[Sliver1]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 9465]]></category>
		<category><![CDATA[백준 9465번]]></category>
		<category><![CDATA[스티커]]></category>
		<category><![CDATA[실버]]></category>
		<category><![CDATA[실버1]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36495</guid>

					<description><![CDATA[<p>백준 9465번 '스티커' 문제에 대한 글입니다. DP 알고리즘을 이용하여 해결하였습니다. (This is an article about BaekJoon Number 9465, the "sticker" problem. It was solved using DP algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9465%eb%b2%88-%ec%8a%a4%ed%8b%b0%ec%bb%a4-c-baekjoon/36495/">백준 9465번 (스티커, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-943dda5b      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#스티커" class="uagb-toc-link__trigger">스티커</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ul></ol>					</div>
									</div>
				</div>
			


<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">스티커 <img decoding="async" width="30" height="38" class="wp-image-37895" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2023/09/Sliver_1.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2023/09/Sliver_1.jpg 1250w, https://lycos7560.com/wp-content/uploads/2023/09/Sliver_1-234x300.jpg 234w, https://lycos7560.com/wp-content/uploads/2023/09/Sliver_1-768x983.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/09/Sliver_1-1200x1536.jpg 1200w" sizes="(max-width: 30px) 100vw, 30px" /></h1>



<p><a href="https://www.acmicpc.net/problem/9465" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/9465</a></p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">1 초</td><td class="has-text-align-left" data-align="left">256 MB</td><td class="has-text-align-left" data-align="left">64690</td><td class="has-text-align-left" data-align="left">30265</td><td class="has-text-align-left" data-align="left">21187</td><td class="has-text-align-left" data-align="left">46.744%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p>상근이의 여동생 상냥이는 문방구에서 스티커 2n개를 구매했다. </p>



<p>스티커는 그림 (a)와 같이 2행 n열로 배치되어 있다. </p>



<p>상냥이는 스티커를 이용해 책상을 꾸미려고 한다.</p>



<p>상냥이가 구매한 스티커의 품질은 매우 좋지 않다. </p>



<p>스티커 한 장을 떼면, 그 스티커와 변을 공유하는 스티커는 모두 찢어져서 사용할 수 없게 된다. </p>



<p>즉, 뗀 스티커의 왼쪽, 오른쪽, 위, 아래에 있는 스티커는 사용할 수 없게 된다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="976" height="247" src="https://lycos7560.com/wp-content/uploads/2023/08/image-8.png" alt="" class="wp-image-36497" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-8.png 976w, https://lycos7560.com/wp-content/uploads/2023/08/image-8-300x76.png 300w, https://lycos7560.com/wp-content/uploads/2023/08/image-8-768x194.png 768w" sizes="(max-width: 976px) 100vw, 976px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p>모든 스티커를 붙일 수 없게된 상냥이는 각 스티커에 점수를 매기고, 점수의 합이 최대가 되게 스티커를 떼어내려고 한다. </p>



<p>먼저, 그림 (b)와 같이 각 스티커에 점수를 매겼다. 상냥이가 뗄 수 있는 스티커의 점수의 최댓값을 구하는 프로그램을 작성하시오. </p>



<p>즉, 2n개의 스티커 중에서 점수의 합이 최대가 되면서 서로 변을 공유 하지 않는 스티커 집합을 구해야 한다.</p>



<p>위의 그림의 경우에 점수가 50, 50, 100, 60인 스티커를 고르면, 점수는 260이 되고 이 것이 최대 점수이다. </p>



<p>가장 높은 점수를 가지는 두 스티커 (100과 70)은 변을 공유하기 때문에, 동시에 뗄 수 없다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p>첫째 줄에 테스트 케이스의 개수 T가 주어진다. </p>



<p>각 테스트 케이스의 첫째 줄에는 n (1 ≤ n ≤ 100,000)이 주어진다. </p>



<p>다음 두 줄에는 n개의 정수가 주어지며, 각 정수는 그 위치에 해당하는 스티커의 점수이다. </p>



<p>연속하는 두 정수 사이에는 빈 칸이 하나 있다. </p>



<p>점수는 0보다 크거나 같고, 100보다 작거나 같은 정수이다.&nbsp;</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p>각 테스트 케이스 마다, 2n개의 스티커 중에서 두 변을 공유하지 않는 스티커 점수의 최댓값을 출력한다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">2
5
50 10 100 20 40
30 50 70 10 60
7
10 30 10 50 100 20 40
20 40 30 50 60 20 80</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">260
290</pre>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">출처</h3>



<p><a href="https://www.acmicpc.net/category/1">ICPC</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/7">Regionals</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/42">Asia Pacific</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/211">Korea</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/1169">Asia Regional &#8211; Daejeon 2013</a>&nbsp;K번</p>



<ul class="wp-block-list">
<li>문제를 번역한 사람:&nbsp;<a href="https://www.acmicpc.net/user/baekjoon">baekjoon</a></li>



<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/jh05013">jh05013</a>,&nbsp;<a href="https://www.acmicpc.net/user/seoyeon1018">seoyeon1018</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">알고리즘 분류</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/25">다이나믹 프로그래밍</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<h2 class="wp-block-heading has-large-font-size">통과된 코드</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>

using namespace std;

int _T, _N, _Res = 0;
int _Table[2][100000];
int _SumTable[2][100000];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> _T;
	while (_T--) {
		cin >> _N;
		for (int i = 0; i &lt; _N; i++) {
			_SumTable[0][i] = 0;
			_SumTable[1][i] = 0;
			_Table[0][i] = 0;
			_Table[1][i] = 0;
		}

		for (int i = 0; i &lt; 2; i++)
			for (int j = 0; j &lt; _N; j++)
				cin >> _Table[i][j];

		_SumTable[0][0] = _Table[0][0];
		_SumTable[1][0] = _Table[1][0];
		_SumTable[0][1] = _Table[1][0] + _Table[0][1];
		_SumTable[1][1] = _Table[0][0] + _Table[1][1];

		for (int i = 2; i &lt; _N; i++) {
			_SumTable[0][i] = max(_SumTable[1][i - 1], _SumTable[1][i - 2]) + _Table[0][i];
			_SumTable[1][i] = max(_SumTable[0][i - 1], _SumTable[0][i - 2]) + _Table[1][i];
		}

		_Res = 0;
		for (int i = 0; i &lt; 2; i++) {
			_N--;
			if (_N &lt; 0) break;
			_Res = max(_Res, max(_SumTable[0][_N], _SumTable[1][_N]));
		}

		cout &lt;&lt; _Res&lt;&lt; "\n";

	}

	return 0;
}</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1060" height="86" src="https://lycos7560.com/wp-content/uploads/2023/08/image-9.png" alt="" class="wp-image-36500" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-9.png 1060w, https://lycos7560.com/wp-content/uploads/2023/08/image-9-300x24.png 300w, https://lycos7560.com/wp-content/uploads/2023/08/image-9-768x62.png 768w" sizes="(max-width: 1060px) 100vw, 1060px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-format="autorelaxed"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="4386247858"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9465%eb%b2%88-%ec%8a%a4%ed%8b%b0%ec%bb%a4-c-baekjoon/36495/">백준 9465번 (스티커, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9465%eb%b2%88-%ec%8a%a4%ed%8b%b0%ec%bb%a4-c-baekjoon/36495/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 13398번 (연속합 2, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-13398%eb%b2%88-%ec%97%b0%ec%86%8d%ed%95%a9-2-c-baekjoon/36305/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-13398%eb%b2%88-%ec%97%b0%ec%86%8d%ed%95%a9-2-c-baekjoon/36305/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 23 Jul 2023 13:34:59 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[13398]]></category>
		<category><![CDATA[13398번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 13398]]></category>
		<category><![CDATA[백준 13398번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[연속합]]></category>
		<category><![CDATA[연속합 2]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36305</guid>

					<description><![CDATA[<p>백준 13398번 '연속합 2' 문제에 대한 글입니다. 다이나믹 프로그래밍을 이용하여 해결하였습니다. (This article is about Baek Joon Number 13398 'Continuous Combination 2' It was solved using dynamic programming.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-13398%eb%b2%88-%ec%97%b0%ec%86%8d%ed%95%a9-2-c-baekjoon/36305/">백준 13398번 (연속합 2, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-9e7b9b14      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#연속합-2" class="uagb-toc-link__trigger">연속합 2</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#시간-초과-코드-brute-force" class="uagb-toc-link__trigger">시간 초과 코드 (Brute Force)</a></ul></ol>					</div>
									</div>
				</div>
			


<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">연속합 2</h1>



<p><a href="https://www.acmicpc.net/problem/13398" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/13398</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">2 초</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">20353</td><td class="has-text-align-left" data-align="left">6150</td><td class="has-text-align-left" data-align="left">4550</td><td class="has-text-align-left" data-align="left">29.754%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p>n개의 정수로 이루어진 임의의 수열이 주어진다. </p>



<p>우리는 이 중 연속된 몇 개의 수를 선택해서 구할 수 있는 합 중 가장 큰 합을 구하려고 한다. </p>



<p>단, 수는 한 개 이상 선택해야 한다. 또, 수열에서 수를 하나 제거할 수 있다. (제거하지 않아도 된다)</p>



<p>예를 들어서 10, -4, 3, 1, 5, 6, -35, 12, 21, -1 이라는 수열이 주어졌다고 하자. </p>



<p>여기서 수를 제거하지 않았을 때의&nbsp;정답은 12+21인 33이 정답이 된다.</p>



<p>만약, -35를 제거한다면, 수열은&nbsp;10, -4, 3, 1, 5, 6, 12, 21, -1이 되고, </p>



<p>여기서 정답은 10-4+3+1+5+6+12+21인 54가 된다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p>첫째 줄에 정수 n(1&nbsp;≤ n ≤ 100,000)이 주어지고 둘째 줄에는 n개의 정수로 이루어진 수열이 주어진다. </p>



<p>수는 -1,000보다 크거나 같고, 1,000보다 작거나 같은 정수이다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p>첫째 줄에 답을 출력한다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">10
10 -4 3 1 5 6 -35 12 21 -1</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">54</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">출처</h3>



<ul class="wp-block-list">
<li>문제를 만든 사람:&nbsp;<a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/dj910401" target="_blank" rel="noreferrer noopener">dj910401</a>,&nbsp;<a href="https://www.acmicpc.net/user/ha_ram" target="_blank" rel="noreferrer noopener">ha_ram</a>,&nbsp;<a href="https://www.acmicpc.net/user/solarmagic" target="_blank" rel="noreferrer noopener">solarmagic</a></li>



<li>문제의 오타를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</a></li>



<li>잘못된 데이터를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/tncks0121" target="_blank" rel="noreferrer noopener">tncks0121</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">알고리즘 분류</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/25" target="_blank" rel="noreferrer noopener">다이나믹 프로그래밍</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<h2 class="wp-block-heading has-large-font-size">시간 초과 코드 (Brute Force)</h2>



<p>N의 범위가 100,000로 모든 경우의 수를 확인하면 시간 복잡도가 O(N^2)이 넘어간다 (대략 O(N^3)?)</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
using namespace std;
int _Arr[100001], _N, _Res = INT32_MIN;
int _DP[100001];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> _N;
	for (int i = 1; i &lt;= _N; i++)
		cin >> _Arr[i];
	for (int i = 1; i &lt;= _N; i++) {
		_DP[i] = _DP[i - 1] + _Arr[i];
		_Res = max(_Res, _DP[i]);
	}

	for (int i = 1; i &lt;= _N; i++)
		for (int j = 0; j &lt;= i - 2; j++) {
			_Res = max(_Res, _DP[i] - _DP[j]);
			for (int k = j + 1; k &lt;= i; k++)
				_Res = max(_Res, _DP[i] - _DP[j] - _Arr[k]);	
		}
	cout &lt;&lt; _Res;
	return 0;
}</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1205" height="57" src="https://lycos7560.com/wp-content/uploads/2023/07/image-48.png" alt="" class="wp-image-36316" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-48.png 1205w, https://lycos7560.com/wp-content/uploads/2023/07/image-48-300x14.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-48-768x36.png 768w" sizes="(max-width: 1205px) 100vw, 1205px" /></figure>



<div style="height:150px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">통과된 코드 (DP)</h3>



<p>DP[0][i] : i번째 수를 포함하여 연속된 수를 선택했을 때의 최대 합을 계산합니다.<br>이전 최대 합인 <code>_DP[0][i-1]</code>과 i번째 수인 <code>_Arr[i]</code>를 더한 값과, i번째 수를 단독으로 선택한 값 중 더 큰 값을 선택하여 저장</p>



<p>DP[1][i] : i번째 수를 제거하고 연속된 수를 선택했을 때의 최대 합을 계산합니다.<br>이전 최대 합인 <code>_DP[0][i-1]</code>과 i번째 수인 <code>_Arr[i]</code>를 더한 값 중 더 큰 값을 선택하여 저장</p>



<p>시간 복잡도는 O(N)</p>



<figure class="wp-block-image size-full"><img decoding="async" width="974" height="153" src="https://lycos7560.com/wp-content/uploads/2023/07/image-50.png" alt="" class="wp-image-36328" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-50.png 974w, https://lycos7560.com/wp-content/uploads/2023/07/image-50-300x47.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-50-768x121.png 768w" sizes="(max-width: 974px) 100vw, 974px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
using namespace std;
int _Arr[100000], _N, _Res;
int _DP[2][100000];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> _N;
	for (int i = 0; i &lt; _N; i++)
		cin >> _Arr[i];
	_Res = _DP[0][0] = _Arr[0];
	_DP[1][0] = 0;
	for (int i = 1; i &lt; _N; i++) {
		_DP[0][i] = max(_DP[0][i - 1] + _Arr[i], _Arr[i]);
		_DP[1][i] = max(_DP[0][i - 1], _DP[1][i - 1] + _Arr[i]);
		_Res = max(_Res, max(_DP[0][i], _DP[1][i]));
	}
	cout &lt;&lt; _Res;
	return 0;
}</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1205" height="100" src="https://lycos7560.com/wp-content/uploads/2023/07/image-49.png" alt="" class="wp-image-36322" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-49.png 1205w, https://lycos7560.com/wp-content/uploads/2023/07/image-49-300x25.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-49-768x64.png 768w" sizes="(max-width: 1205px) 100vw, 1205px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-13398%eb%b2%88-%ec%97%b0%ec%86%8d%ed%95%a9-2-c-baekjoon/36305/">백준 13398번 (연속합 2, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-13398%eb%b2%88-%ec%97%b0%ec%86%8d%ed%95%a9-2-c-baekjoon/36305/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 4811번 (알약, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-4811%eb%b2%88-%ec%95%8c%ec%95%bd-c-baekjoon/36232/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-4811%eb%b2%88-%ec%95%8c%ec%95%bd-c-baekjoon/36232/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 20 Jul 2023 04:39:11 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[4811]]></category>
		<category><![CDATA[4811번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 4811]]></category>
		<category><![CDATA[백준 4811번]]></category>
		<category><![CDATA[수학]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[알약]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36232</guid>

					<description><![CDATA[<p>백준 4811번 ' 알약 ' 문제에 대한 글입니다. 다이나믹 프로그래밍을 이용하여 해결하였습니다. (This is an article about the 'pill' problem of Baekjoon Number 4811. It was solved using dynamic programming.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-4811%eb%b2%88-%ec%95%8c%ec%95%bd-c-baekjoon/36232/">백준 4811번 (알약, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-355fab5d      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#알약" class="uagb-toc-link__trigger">알약</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ul></ol>					</div>
									</div>
				</div>
			


<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">알약</h1>



<p><a href="https://www.acmicpc.net/problem/4811" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/4811</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">1 초</td><td class="has-text-align-left" data-align="left">256 MB</td><td class="has-text-align-left" data-align="left">6484</td><td class="has-text-align-left" data-align="left">4179</td><td class="has-text-align-left" data-align="left">3230</td><td class="has-text-align-left" data-align="left">66.901%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p>70세 박종수 할아버지는 매일 매일 약 반알을 먹는다. </p>



<p>손녀 선영이는 종수 할아버지에게 약이 N개 담긴 병을 선물로 주었다.</p>



<p>첫째 날에 종수는 병에서 약 하나를 꺼낸다. </p>



<p>그 다음, 그 약을 반으로 쪼개서 한 조각은 먹고, 다른 조각은 다시 병에 넣는다.</p>



<p>다음 날부터 종수는 병에서 약을 하나 꺼낸다. (약은 한 조각 전체 일 수도 있고, 쪼갠 반 조각 일 수도 있다) </p>



<p>반 조각이라면 그 약을 먹고, 아니라면 반을 쪼개서 한 조각을 먹고, 다른 조각은 다시 병에 넣는다.</p>



<p>종수는 손녀에게 한 조각을 꺼낸 날에는 W를, 반 조각을 꺼낸 날에는 H 보낸다. </p>



<p>손녀는 할아버지에게 받은 문자를 종이에 기록해 놓는다. </p>



<p>총 2N일이 지나면 길이가 2N인 문자열이 만들어지게 된다. </p>



<p>이때, 가능한 서로 다른 문자열의 개수는 총 몇 개일까?</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p>입력은 최대 1000개의 테스트 케이스로 이루어져 있다. </p>



<p>각 테스트 케이스는 한 줄이며, 병에 들어있는 약의 개수 N ≤ 30 가 주어진다.</p>



<p>입력의 마지막 줄에는 0이 하나 주어진다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p>각 테스트 케이스에 대해서 가능한 문자열의 개수를 출력한다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">6
1
4
2
3
30
0</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">132
1
14
2
5
3814986502092304</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">출처</h3>



<p><a href="https://www.acmicpc.net/category/1" target="_blank" rel="noreferrer noopener">ICPC</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/7" target="_blank" rel="noreferrer noopener">Regionals</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/8" target="_blank" rel="noreferrer noopener">North America</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/41" target="_blank" rel="noreferrer noopener">Rocky Mountain Regional</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/182" target="_blank" rel="noreferrer noopener">2011 Rocky Mountain Regional Contest</a>&nbsp;E번</p>



<ul class="wp-block-list">
<li>문제를 번역한 사람:&nbsp;<a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">알고리즘 분류</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/124" target="_blank" rel="noreferrer noopener">수학</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/25" target="_blank" rel="noreferrer noopener">다이나믹 프로그래밍</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/07/image-44.png" alt="" class="wp-image-36252" width="734" height="788" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-44.png 978w, https://lycos7560.com/wp-content/uploads/2023/07/image-44-279x300.png 279w, https://lycos7560.com/wp-content/uploads/2023/07/image-44-768x825.png 768w" sizes="(max-width: 734px) 100vw, 734px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading has-large-font-size">통과된 코드</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
using namespace std;
int _N;
long long int _DP[31][31];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	for (int i = 0; i &lt;= 30; i++)
		for (int j = 0; j &lt;= 30; j++) {
			// 반쪽이 더 많은 경우는 없다.
			if (i &lt; j) break;
			if (j == 0) _DP[i][j] = 1;
			else _DP[i][j] = _DP[i - 1][j] + _DP[i][j - 1];
		}

	while (true) {
		cin >> _N;
		if (_N == 0) break;
		// 온전한 알약을 N번
		// 반쪽의 알약을 N번 => 다 먹었다.
		cout &lt;&lt; _DP[_N][_N] &lt;&lt; "\n";
	}

	return 0;
}</pre>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1206" height="104" src="https://lycos7560.com/wp-content/uploads/2023/07/image-43.png" alt="" class="wp-image-36241" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-43.png 1206w, https://lycos7560.com/wp-content/uploads/2023/07/image-43-300x26.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-43-768x66.png 768w" sizes="(max-width: 1206px) 100vw, 1206px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-4811%eb%b2%88-%ec%95%8c%ec%95%bd-c-baekjoon/36232/">백준 4811번 (알약, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-4811%eb%b2%88-%ec%95%8c%ec%95%bd-c-baekjoon/36232/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2293번 (동전, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2293%eb%b2%88-%eb%8f%99%ec%a0%84-c-baekjoon/36215/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2293%eb%b2%88-%eb%8f%99%ec%a0%84-c-baekjoon/36215/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 19 Jul 2023 03:25:40 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2293]]></category>
		<category><![CDATA[2293번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[동전]]></category>
		<category><![CDATA[배낭]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 2293]]></category>
		<category><![CDATA[백준 2293번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36215</guid>

					<description><![CDATA[<p>백준 2293번 '동전' 문제에 대한 블로그 글입니다. 다이나믹 프로그래밍을 이용하여 해결하였습니다. (This is a blog post about the issue of 'Coin' in Baekjun 2293. It was solved using dynamic programming.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2293%eb%b2%88-%eb%8f%99%ec%a0%84-c-baekjoon/36215/">백준 2293번 (동전, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-ecb4235e      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#동전" class="uagb-toc-link__trigger">동전</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ul></ol>					</div>
									</div>
				</div>
			


<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">동전</h1>



<p><a href="https://www.acmicpc.net/problem/9084" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/9084</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">1 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">10561</td><td class="has-text-align-left" data-align="left">6888</td><td class="has-text-align-left" data-align="left">5640</td><td class="has-text-align-left" data-align="left">66.384%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p>우리나라 화폐단위, 특히 동전에는 1원, 5원, 10원, 50원, 100원, 500원이 있다. </p>



<p>이 동전들로는 정수의 금액을 만들 수 있으며 그 방법도 여러 가지가 있을 수 있다. </p>



<p>예를 들어, 30원을 만들기 위해서는 1원짜리 30개 또는 10원짜리 2개와 5원짜리 2개 등의 방법이 가능하다.</p>



<p>동전의 종류가 주어질 때에 주어진 금액을 만드는 모든 방법을 세는 프로그램을 작성하시오.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p>입력의 첫 줄에는 테스트 케이스의 개수 T(1 ≤ T ≤ 10)가 주어진다. </p>



<p>각 테스트 케이스의 첫 번째 줄에는 동전의 가지 수 N(1 ≤ N ≤ 20)이 주어지고 </p>



<p>두 번째 줄에는 N가지 동전의 각 금액이 오름차순으로 정렬되어 주어진다. </p>



<p>각 금액은 정수로서 1원부터 10000원까지 있을 수 있으며 공백으로 구분된다. </p>



<p>세 번째 줄에는 주어진 N가지 동전으로 만들어야 할 금액 M(1 ≤ M ≤ 10000)이 주어진다.</p>



<p>편의를 위해 방법의 수는 2<sup>31</sup>&nbsp;&#8211; 1 보다 작고, 같은 동전이 여러 번 주어지는 경우는 없다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p>각 테스트 케이스에 대해 입력으로 주어지는 N가지 동전으로 금액 M을 만드는 모든 방법의 수를 한 줄에 하나씩 출력한다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">3
2
1 2
1000
3
1 5 10
100
2
5 7
22</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">501
121
1</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">출처</h3>



<p><a href="https://www.acmicpc.net/category/1" target="_blank" rel="noreferrer noopener">ICPC</a> > <a href="https://www.acmicpc.net/category/7" target="_blank" rel="noreferrer noopener">Regionals</a> > <a href="https://www.acmicpc.net/category/42" target="_blank" rel="noreferrer noopener">Asia Pacific</a> > <a href="https://www.acmicpc.net/category/211" target="_blank" rel="noreferrer noopener">Korea</a> > <a href="https://www.acmicpc.net/category/256" target="_blank" rel="noreferrer noopener">Nationwide Internet Competition</a> > <a href="https://www.acmicpc.net/category/detail/1090" target="_blank" rel="noreferrer noopener">Seoul Nationalwide Internet Competition 2003</a> F번</p>



<ul class="wp-block-list">
<li>문제의 오타를 찾은 사람: <a href="https://www.acmicpc.net/user/mwy3055" target="_blank" rel="noreferrer noopener">mwy3055</a></li>



<li>빠진 조건을 찾은 사람: <a href="https://www.acmicpc.net/user/thak00" target="_blank" rel="noreferrer noopener">thak00</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">알고리즘 분류</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/25" target="_blank" rel="noreferrer noopener">다이나믹 프로그래밍</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/148" target="_blank" rel="noreferrer noopener">배낭 문제</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<figure class="wp-block-embed is-type-wp-embed is-provider-어제와-내일의-나-그-사이의-이야기 wp-block-embed-어제와-내일의-나-그-사이의-이야기"><div class="wp-block-embed__wrapper">
<blockquote class="wp-embedded-content" data-secret="2AkV74gOIc"><a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2293%eb%b2%88-%eb%8f%99%ec%a0%84-1-c-baekjoon/36200/">백준 2293번 (동전 1, C++) [BAEKJOON]</a></blockquote><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  title="&#8220;백준 2293번 (동전 1, C++) [BAEKJOON]&#8221; &#8212; 어제와 내일의 나 그 사이의 이야기" src="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2293%eb%b2%88-%eb%8f%99%ec%a0%84-1-c-baekjoon/36200/embed/#?secret=JSfYpwgbXT#?secret=2AkV74gOIc" data-secret="2AkV74gOIc" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>



<p>백준 2293번 동전 1과 같은 문제 입니다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading has-large-font-size">통과된 코드</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
using namespace std;
int _N, _M, _T;
int _Coin[20], _DP[10001];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> _T;
	for (int i = 0; i &lt; _T; i++) {
		cin >> _N;
		for (int i = 0; i &lt; _N; i++)
			cin >> _Coin[i];
		cin >> _M;
		_DP[0] = 1;
		for (int i = 0; i &lt; _N; i++)
			for (int j = _Coin[i]; j &lt;= _M; j++)
				_DP[j] += _DP[j - _Coin[i]];
		cout &lt;&lt; _DP[_M] &lt;&lt; "\n";
		for (int i = 0; i &lt;= _M; i++)
			_DP[i] = 0;
	}
	return 0;
}</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1212" height="98" src="https://lycos7560.com/wp-content/uploads/2023/07/image-42.png" alt="" class="wp-image-36224" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-42.png 1212w, https://lycos7560.com/wp-content/uploads/2023/07/image-42-300x24.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-42-768x62.png 768w" sizes="(max-width: 1212px) 100vw, 1212px" /></figure>



<div style="height:42px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2293%eb%b2%88-%eb%8f%99%ec%a0%84-c-baekjoon/36215/">백준 2293번 (동전, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2293%eb%b2%88-%eb%8f%99%ec%a0%84-c-baekjoon/36215/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2293번 (동전 1, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2293%eb%b2%88-%eb%8f%99%ec%a0%84-1-c-baekjoon/36200/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2293%eb%b2%88-%eb%8f%99%ec%a0%84-1-c-baekjoon/36200/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 18 Jul 2023 01:32:16 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2293]]></category>
		<category><![CDATA[2293번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[동전 1]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 2293]]></category>
		<category><![CDATA[백준 2293번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36200</guid>

					<description><![CDATA[<p>백준 2293번 '동전 1' 문제에 대한 글입니다.<br />
다이나믹 프로그래밍을 이용하여 해결하였습니다. (<br />
This is a blog post about the problem of 'Coin 1' in Baekjun 2293. I solved the problem using dynamic programming. )</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2293%eb%b2%88-%eb%8f%99%ec%a0%84-1-c-baekjoon/36200/">백준 2293번 (동전 1, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-1fc1cb68      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#동전-1" class="uagb-toc-link__trigger">동전 1</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ul></ol>					</div>
									</div>
				</div>
			


<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">동전 1</h1>



<p><a href="https://www.acmicpc.net/problem/2293" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/2293</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">0.5 초 (추가 시간 없음)</td><td class="has-text-align-left" data-align="left">4 MB</td><td class="has-text-align-left" data-align="left">55412</td><td class="has-text-align-left" data-align="left">25613</td><td class="has-text-align-left" data-align="left">19398</td><td class="has-text-align-left" data-align="left">46.232%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p>n가지 종류의 동전이 있다. 각각의 동전이 나타내는 가치는 다르다. </p>



<p>이 동전을 적당히 사용해서, 그 가치의 합이 k원이 되도록 하고 싶다. </p>



<p>그 경우의 수를 구하시오. 각각의 동전은 몇 개라도 사용할 수 있다.</p>



<p>사용한 동전의 구성이 같은데, 순서만 다른 것은 같은 경우이다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p>첫째 줄에 n, k가 주어진다. (1 ≤ n ≤ 100, 1 ≤ k ≤ 10,000) </p>



<p>다음 n개의 줄에는 각각의 동전의 가치가 주어진다. </p>



<p>동전의 가치는 100,000보다 작거나 같은 자연수이다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p>첫째 줄에 경우의 수를 출력한다. 경우의 수는 2<sup>31</sup>보다 작다.</p>



<div style="height:39px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">3 10
1
2
5</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">10</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">출처</h3>



<ul class="wp-block-list">
<li>어색한 표현을 찾은 사람: <a href="https://www.acmicpc.net/user/dbfldkfdbgml" target="_blank" rel="noreferrer noopener">dbfldkfdbgml</a></li>



<li>빠진 조건을 찾은 사람: <a href="https://www.acmicpc.net/user/goodcrane3" target="_blank" rel="noreferrer noopener">goodcrane3</a></li>



<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">알고리즘 분류</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/25" target="_blank" rel="noreferrer noopener">다이나믹 프로그래밍</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/07/KakaoTalk_20230718_102905744.jpg" alt="" class="wp-image-36212" width="1199" height="1440" srcset="https://lycos7560.com/wp-content/uploads/2023/07/KakaoTalk_20230718_102905744.jpg 1598w, https://lycos7560.com/wp-content/uploads/2023/07/KakaoTalk_20230718_102905744-250x300.jpg 250w, https://lycos7560.com/wp-content/uploads/2023/07/KakaoTalk_20230718_102905744-768x923.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/07/KakaoTalk_20230718_102905744-1278x1536.jpg 1278w" sizes="(max-width: 1199px) 100vw, 1199px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading has-large-font-size">통과된 코드</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
using namespace std;
int _N, _K, _Temp, _Coin[100], _DP[10001];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> _N >> _K;
	for (int i = 0; i &lt; _N; i++)
		cin >> _Coin[i];
	_DP[0] = 1;
	for (int i = 0; i &lt; _N; i++)
		for (int j = _Coin[i]; j &lt;= _K; j++)
			_DP[j] = _DP[j] + _DP[j - _Coin[i]];
	cout &lt;&lt; _DP[_K];
	return 0;
}</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1201" height="100" src="https://lycos7560.com/wp-content/uploads/2023/07/image-41.png" alt="" class="wp-image-36208" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-41.png 1201w, https://lycos7560.com/wp-content/uploads/2023/07/image-41-300x25.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-41-768x64.png 768w" sizes="(max-width: 1201px) 100vw, 1201px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2293%eb%b2%88-%eb%8f%99%ec%a0%84-1-c-baekjoon/36200/">백준 2293번 (동전 1, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2293%eb%b2%88-%eb%8f%99%ec%a0%84-1-c-baekjoon/36200/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 17070번 (파이프 옮기기 1, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17070%eb%b2%88-%ed%8c%8c%ec%9d%b4%ed%94%84-%ec%98%ae%ea%b8%b0%ea%b8%b0-1-c-baekjoon/34406/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17070%eb%b2%88-%ed%8c%8c%ec%9d%b4%ed%94%84-%ec%98%ae%ea%b8%b0%ea%b8%b0-1-c-baekjoon/34406/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 03 May 2023 12:28:58 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[<algorithm>]]></category>
		<category><![CDATA[17070]]></category>
		<category><![CDATA[17070번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 17070]]></category>
		<category><![CDATA[백준 17070번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[파이프 옮기기 1]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34406</guid>

					<description><![CDATA[<p>백준 17070번 '파이프 옮기기 1' 문제에 대한 글입니다. BFS 탐색 또는 DP 알고리즘을 이용하여 해결이 가능합니다. (This article is about Baekjoon Number 17070 'Pipe Transfer 1' problem. It can be solved using BFS search or DP algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17070%eb%b2%88-%ed%8c%8c%ec%9d%b4%ed%94%84-%ec%98%ae%ea%b8%b0%ea%b8%b0-1-c-baekjoon/34406/">백준 17070번 (파이프 옮기기 1, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-0725da64      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#파이프-옮기기-1" class="uagb-toc-link__trigger">파이프 옮기기 1</a><li class="uagb-toc__list"><a href="#통과된-코드-bfs" class="uagb-toc-link__trigger">통과된 코드 (BFS)</a><li class="uagb-toc__list"><a href="#통과된-코드-dp" class="uagb-toc-link__trigger">통과된 코드 (DP)</a></ol>					</div>
									</div>
				</div>
			


<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">파이프 옮기기 1</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/17070" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/17070</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">1 초 (추가 시간 없음)</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">31068</td><td class="has-text-align-left" data-align="left">14557</td><td class="has-text-align-left" data-align="left">9962</td><td class="has-text-align-left" data-align="left">45.783%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size">유현이가 새 집으로 이사했다. 새 집의 크기는 N×N의 격자판으로 나타낼 수 있고, </p>



<p class="has-medium-font-size">1×1크기의 정사각형 칸으로 나누어져 있다. </p>



<p class="has-medium-font-size">각각의 칸은 (r, c)로 나타낼 수 있다. 여기서 r은 행의 번호, c는 열의 번호이고, </p>



<p class="has-medium-font-size">행과 열의 번호는 1부터 시작한다. </p>



<p class="has-medium-font-size">각각의 칸은 빈 칸이거나 벽이다.</p>



<p class="has-medium-font-size">오늘은 집 수리를 위해서 파이프 하나를 옮기려고 한다. </p>



<p class="has-medium-font-size">파이프는 아래와 같은 형태이고, 2개의 연속된 칸을 차지하는 크기이다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="292" height="156" src="https://lycos7560.com/wp-content/uploads/2023/05/image.png" alt="" class="wp-image-34408"/></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">파이프는 회전시킬 수 있으며, 아래와 같이 3가지 방향이 가능하다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="948" height="294" src="https://lycos7560.com/wp-content/uploads/2023/05/image-1.png" alt="" class="wp-image-34409" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-1.png 948w, https://lycos7560.com/wp-content/uploads/2023/05/image-1-300x93.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-1-768x238.png 768w" sizes="(max-width: 948px) 100vw, 948px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">파이프는 매우 무겁기 때문에, 유현이는 파이프를 밀어서 이동시키려고 한다. </p>



<p class="has-medium-font-size">벽에는 새로운 벽지를 발랐기 때문에, 파이프가 벽을 긁으면 안 된다. </p>



<p class="has-medium-font-size">즉, 파이프는 항상 빈 칸만 차지해야 한다.</p>



<p class="has-medium-font-size">파이프를 밀 수 있는 방향은 총 3가지가 있으며,&nbsp;→,&nbsp;<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2198.png" alt="↘" class="wp-smiley" style="height: 1em; max-height: 1em;" />,&nbsp;↓ 방향이다. </p>



<p class="has-medium-font-size">파이프는 밀면서 회전시킬 수 있다. 회전은 45도만 회전시킬 수 있으며, </p>



<p class="has-medium-font-size">미는 방향은 오른쪽, 아래, 또는 오른쪽 아래 대각선 방향이어야 한다.</p>



<p class="has-medium-font-size">파이프가 가로로 놓여진 경우에&nbsp;가능한 이동 방법은 총 2가지, </p>



<p class="has-medium-font-size">세로로 놓여진 경우에는 2가지, 대각선 방향으로 놓여진 경우에는 3가지가 있다.</p>



<p class="has-medium-font-size">아래 그림은 파이프가 놓여진 방향에 따라서 이동할 수 있는 방법을 모두 나타낸 것이고, </p>



<p class="has-medium-font-size">꼭 빈 칸이어야 하는 곳은 색으로 표시되어져 있다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1195" height="422" src="https://lycos7560.com/wp-content/uploads/2023/05/image-2.png" alt="" class="wp-image-34410" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-2.png 1195w, https://lycos7560.com/wp-content/uploads/2023/05/image-2-300x106.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-2-768x271.png 768w" sizes="(max-width: 1195px) 100vw, 1195px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">가로</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1179" height="416" src="https://lycos7560.com/wp-content/uploads/2023/05/image-3.png" alt="" class="wp-image-34411" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-3.png 1179w, https://lycos7560.com/wp-content/uploads/2023/05/image-3-300x106.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-3-768x271.png 768w" sizes="(max-width: 1179px) 100vw, 1179px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">세로</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1797" height="421" src="https://lycos7560.com/wp-content/uploads/2023/05/image-4.png" alt="" class="wp-image-34412" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-4.png 1797w, https://lycos7560.com/wp-content/uploads/2023/05/image-4-300x70.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-4-768x180.png 768w, https://lycos7560.com/wp-content/uploads/2023/05/image-4-1536x360.png 1536w" sizes="(max-width: 1797px) 100vw, 1797px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">대각선</p>



<p class="has-medium-font-size">가장 처음에 파이프는&nbsp;(1, 1)와 (1, 2)를 차지하고 있고, 방향은 가로이다. </p>



<p class="has-medium-font-size">파이프의 한쪽 끝을 (N, N)로 이동시키는 방법의 개수를 구해보자.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size">첫째 줄에 집의 크기 N(3 ≤ N ≤ 16)이 주어진다. </p>



<p class="has-medium-font-size">둘째 줄부터 N개의 줄에는 집의 상태가 주어진다. 빈 칸은 0, 벽은 1로 주어진다. </p>



<p class="has-medium-font-size">(1, 1)과 (1, 2)는 항상 빈 칸이다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size">첫째 줄에 파이프의 한쪽 끝을 (N, N)으로 이동시키는 방법의 수를 출력한다. </p>



<p class="has-medium-font-size">이동시킬 수 없는 경우에는 0을 출력한다. </p>



<p class="has-medium-font-size">방법의 수는 항상 1,000,000보다 작거나 같다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">3
0 0 0
0 0 0
0 0 0</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">3</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5
0 0 1 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">0</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 4</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">6
0 0 0 0 0 0
0 1 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 4</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">13</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<ul class="wp-block-list">
<li>문제를 만든 사람:&nbsp;<a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/djm03178" target="_blank" rel="noreferrer noopener">djm03178</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/25" target="_blank" rel="noreferrer noopener">다이나믹 프로그래밍</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/7" target="_blank" rel="noreferrer noopener">그래프 이론</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/11" target="_blank" rel="noreferrer noopener">그래프 탐색</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<h1 class="wp-block-heading">통과된 코드 (BFS)</h1>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_203812154.jpg" alt="" class="wp-image-34417" width="1200" height="473" srcset="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_203812154.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_203812154-300x118.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_203812154-768x302.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_203812154-1536x605.jpg 1536w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;queue>
#include &lt;tuple>
using namespace std;
// 우측, 하단, 대각선
int _DxDy[3][2] = { { 0, 1},{ 1, 0},{ 1, 1} };
bool _MapArr[17][17];
// x좌표, y좌표, 파이프의 상태
// 0 = 가로 , 1 = 세로 , 2 = 대각선
queue&lt;tuple&lt;int, int, int>> _BFSQ;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    int _N, _Res = 0;
	cin >> _N;
	for (int i = 1; i &lt;= _N; i++) {
		for (int j = 1; j &lt;= _N; j++) {
			cin >> _MapArr[i][j];
		}
	}

	tuple&lt;int, int, int> _Temp = make_tuple(1, 2, 0);
	_BFSQ.push(_Temp);
	while (!_BFSQ.empty()) {
		_Temp = _BFSQ.front();
		_BFSQ.pop();
		for (int i = 0; i &lt; 3; i++) {
			if (get&lt;2>(_Temp) == 0 &amp;&amp; i == 1 || get&lt;2>(_Temp) == 1 &amp;&amp; i == 0) continue;
			int _dx = get&lt;0>(_Temp) + _DxDy[i][0];
			int _dy = get&lt;1>(_Temp) + _DxDy[i][1];
			if (_dx > _N || _dy > _N || _dx &lt;= 0 || _dy &lt;= 0 || _MapArr[_dx][_dy]) continue;
			if (i == 2) { // 대각선 방향 우측, 하단부 확인
				if (_MapArr[get&lt;0>(_Temp) + _DxDy[0][0]][get&lt;1>(_Temp) + _DxDy[0][1]] ||
					_MapArr[get&lt;0>(_Temp) + _DxDy[1][0]][get&lt;1>(_Temp) + _DxDy[1][1]]) continue;
			}
			if (_dx == _N &amp;&amp; _dy == _N) {
				_Res++;
				continue;
			}
			tuple&lt;int, int, int> _Temp2 = make_tuple(_dx, _dy, i);
			_BFSQ.push(_Temp2);
		}
	}
	cout &lt;&lt; _Res;

    return 0;
}
</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/05/image-5.png" alt="" class="wp-image-34414" width="1160" height="94" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-5.png 965w, https://lycos7560.com/wp-content/uploads/2023/05/image-5-300x24.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-5-768x62.png 768w" sizes="(max-width: 1160px) 100vw, 1160px" /></figure>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">BFS 탐색을 이용한 결과 생각보다 시간이 많이 걸리고 메모리도 많이 사용한다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">통과된 코드 (DP)</h1>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">DP 알고리즘을 이용한 해결법이 더 효율적</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_212725963.jpg" alt="" class="wp-image-34424" width="1200" height="1410" srcset="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_212725963.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_212725963-255x300.jpg 255w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_212725963-768x902.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_212725963-1307x1536.jpg 1307w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
using namespace std;
// 0 가로, 1 세로, 2 대각선
int _DpArr[3][17][17];
bool _MapArr[17][17];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int _N;
    cin >> _N;  
    for (int i = 1; i &lt;= _N; ++i)
        for (int j = 1; j &lt;= _N; ++j)
            cin >> _MapArr[i][j];
    // 파이프의 상태, (1, 2) 시작
    _DpArr[0][1][2] = 1;
    // Tabulation: Bottom Up(표, 상향식) DP
    for (int i = 1; i &lt;= _N; ++i) {
        for (int j = 1; j &lt;= _N; ++j) {
            if (_MapArr[i][j]) continue; // 움직일 위치가 벽이 라면 넘어간다.
            // 가로 상태로 이동이 가능한 경우 => 전 상태가 우측 or 대각선인 경우
            _DpArr[0][i][j] += _DpArr[0][i][j - 1] + _DpArr[2][i][j - 1];
            // 세로 상태로 이동이 가능한 경우 => 전 상태가 하단 or 대각선인 경우
            _DpArr[1][i][j] += _DpArr[1][i - 1][j] + _DpArr[2][i - 1][j];
            // 대각선 상태로 이동이 가능한 조건 체크 => 우측 + 하단에 벽이 있는지 확인이 필요
            if (_MapArr[i][j - 1] || _MapArr[i - 1][j]) continue;
            // 대각선 상태로 이동이 가능한 경우 => 모든 경우 가능
            _DpArr[2][i][j] += _DpArr[0][i - 1][j - 1] + _DpArr[1][i - 1][j - 1] + _DpArr[2][i - 1][j - 1];
        }
    }
    // DP연산을 마친후에 결과 종합
    // _N,_N 에 도착한 상태가 가로, 세로, 대각선 상태를 전부 더해준다.
    cout &lt;&lt; _DpArr[0][_N][_N] + _DpArr[1][_N][_N] + _DpArr[2][_N][_N];
    return 0;
}</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/05/image-6.png" alt="" class="wp-image-34421" width="1165" height="114" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-6.png 829w, https://lycos7560.com/wp-content/uploads/2023/05/image-6-300x29.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-6-768x75.png 768w" sizes="(max-width: 1165px) 100vw, 1165px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17070%eb%b2%88-%ed%8c%8c%ec%9d%b4%ed%94%84-%ec%98%ae%ea%b8%b0%ea%b8%b0-1-c-baekjoon/34406/">백준 17070번 (파이프 옮기기 1, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17070%eb%b2%88-%ed%8c%8c%ec%9d%b4%ed%94%84-%ec%98%ae%ea%b8%b0%ea%b8%b0-1-c-baekjoon/34406/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1932번 (정수 삼각형, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1932%eb%b2%88-%ec%a0%95%ec%88%98-%ec%82%bc%ea%b0%81%ed%98%95-c-baekjoon/34387/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1932%eb%b2%88-%ec%a0%95%ec%88%98-%ec%82%bc%ea%b0%81%ed%98%95-c-baekjoon/34387/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 28 Apr 2023 00:12:02 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34387</guid>

					<description><![CDATA[<p>백준 1932번 '정수 삼각형' 문제에 대한 글입니다. 다이나믹 프로그래밍 알고리즘을 이용하여 해결하였습니다. (This article is about the question of Baekjoon<br />
Number 1932 'integer triangle'. It was solved using a dynamic programming algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1932%eb%b2%88-%ec%a0%95%ec%88%98-%ec%82%bc%ea%b0%81%ed%98%95-c-baekjoon/34387/">백준 1932번 (정수 삼각형, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-282e853d      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#구간-합-구하기-5" class="uagb-toc-link__trigger">구간 합 구하기 5</a><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ol>					</div>
									</div>
				</div>
			


<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">구간 합 구하기 5</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/1932" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1932</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">2 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">78199</td><td class="has-text-align-left" data-align="left">44868</td><td class="has-text-align-left" data-align="left">33793</td><td class="has-text-align-left" data-align="left">59.091%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<pre class="wp-block-preformatted">        7
      3   8
    8   1   0
  2   7   4   4
4   5   2   6   5</pre>



<p class="has-medium-font-size">위 그림은 크기가 5인 정수 삼각형의 한 모습이다.</p>



<p class="has-medium-font-size">맨 위층 7부터 시작해서 아래에 있는 수 중 하나를 선택하여 아래층으로 내려올 때, </p>



<p class="has-medium-font-size">이제까지 선택된 수의 합이 최대가 되는 경로를 구하는 프로그램을 작성하라. </p>



<p class="has-medium-font-size">아래층에 있는 수는 현재 층에서 선택된 수의 대각선 왼쪽 또는 대각선 오른쪽에 있는 것 중에서만 선택할 수 있다.</p>



<p class="has-medium-font-size">삼각형의 크기는 1 이상 500 이하이다. 삼각형을 이루고 있는 각 수는 모두 정수이며, 범위는 0 이상 9999 이하이다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size">첫째 줄에 삼각형의 크기 n(1 ≤ n ≤ 500)이 주어지고, </p>



<p class="has-medium-font-size">둘째 줄부터 n+1번째 줄까지 정수 삼각형이 주어진다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size">첫째 줄에 합이 최대가 되는 경로에 있는 수의 합을 출력한다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">30</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<p><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a> > <a href="https://www.acmicpc.net/category/99" target="_blank" rel="noreferrer noopener">International Olympiad in Informatics</a> > <a href="https://www.acmicpc.net/category/570" target="_blank" rel="noreferrer noopener">IOI 1994</a> > <a href="https://www.acmicpc.net/category/detail/541" target="_blank" rel="noreferrer noopener">Day 1</a> 1번</p>



<p><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a> > <a href="https://www.acmicpc.net/category/106" target="_blank" rel="noreferrer noopener">USA Computing Olympiad</a> > <a href="https://www.acmicpc.net/category/192" target="_blank" rel="noreferrer noopener">2005-2006 Season</a> > <a href="https://www.acmicpc.net/category/194" target="_blank" rel="noreferrer noopener">USACO December 2005 Contest</a> > <a href="https://www.acmicpc.net/category/detail/3393" target="_blank" rel="noreferrer noopener">Bronze</a> ?번</p>



<p><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a> > <a href="https://www.acmicpc.net/category/106" target="_blank" rel="noreferrer noopener">USA Computing Olympiad</a> > <a href="https://www.acmicpc.net/category/269" target="_blank" rel="noreferrer noopener">1999-2000 Season</a> > <a href="https://www.acmicpc.net/category/766" target="_blank" rel="noreferrer noopener">USACO Fall 1999 Contest</a> > <a href="https://www.acmicpc.net/category/detail/3434" target="_blank" rel="noreferrer noopener">Gold</a> 1번</p>



<ul class="wp-block-list">
<li>문제의 오타를 찾은 사람: <a href="https://www.acmicpc.net/user/apjw6112" target="_blank" rel="noreferrer noopener">apjw6112</a>, <a href="https://www.acmicpc.net/user/Martian" target="_blank" rel="noreferrer noopener">Martian</a>, <a href="https://www.acmicpc.net/user/paranocean" target="_blank" rel="noreferrer noopener">paranocean</a></li>



<li>잘못된 조건을 찾은 사람: <a href="https://www.acmicpc.net/user/djm03178">djm</a><a href="https://www.acmicpc.net/user/djm03178" target="_blank" rel="noreferrer noopener">0</a><a href="https://www.acmicpc.net/user/djm03178">3178</a></li>



<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/eunhyekim1223" target="_blank" rel="noreferrer noopener">eunhyekim1223</a>, <a href="https://www.acmicpc.net/user/hwangtmdals" target="_blank" rel="noreferrer noopener">hwangtmdals</a></li>



<li>잘못된 데이터를 찾은 사람: <a href="https://www.acmicpc.net/user/thanatos0128" target="_blank" rel="noreferrer noopener">thanatos0128</a></li>
</ul>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/25" target="_blank" rel="noreferrer noopener">다이나믹 프로그래밍</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<h1 class="wp-block-heading">통과된 코드</h1>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/04/image-27.jpg" alt="" class="wp-image-34392" width="705" height="520" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-27.jpg 1238w, https://lycos7560.com/wp-content/uploads/2023/04/image-27-300x221.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/04/image-27-768x567.jpg 768w" sizes="(max-width: 705px) 100vw, 705px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
using namespace std;
int _Arr[501][501];
int _Dp[501][501];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int _N, _Res = 0;
    cin >> _N;
    cin >> _Arr[1][1];
    _Dp[1][1] = _Arr[1][1];
    for (int i = 2; i &lt;= _N; i++) {
        for (int j = 1; j &lt;= i; j++) {
            cin >> _Arr[i][j];
            _Dp[i][j] = max(_Dp[i - 1][j - 1], _Dp[i - 1][j]) + _Arr[i][j];
        }
    }
    for (int i = 1; i &lt;= _N; i++)
        _Res = max(_Dp[_N][i], _Res);
    cout &lt;&lt; _Res;
    return 0;
}
</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">dp[1][1]을 초기화하지 않아서 틀렸다. </p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/04/image-26.png" alt="" class="wp-image-34389" width="871" height="121" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-26.png 829w, https://lycos7560.com/wp-content/uploads/2023/04/image-26-300x42.png 300w, https://lycos7560.com/wp-content/uploads/2023/04/image-26-768x107.png 768w" sizes="(max-width: 871px) 100vw, 871px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1932%eb%b2%88-%ec%a0%95%ec%88%98-%ec%82%bc%ea%b0%81%ed%98%95-c-baekjoon/34387/">백준 1932번 (정수 삼각형, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1932%eb%b2%88-%ec%a0%95%ec%88%98-%ec%82%bc%ea%b0%81%ed%98%95-c-baekjoon/34387/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 9251번 (LCS, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9251%eb%b2%88-lcs-c-baekjoon/34481/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9251%eb%b2%88-lcs-c-baekjoon/34481/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 25 Apr 2023 21:56:53 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[9251]]></category>
		<category><![CDATA[9251번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[LCS]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[문자열]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 9251]]></category>
		<category><![CDATA[백준 9251번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[추가 반례]]></category>
		<category><![CDATA[추가 예제]]></category>
		<category><![CDATA[추가반례]]></category>
		<category><![CDATA[추가예제]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34481</guid>

					<description><![CDATA[<p>백준 9251번 'LCS' 문제에 대한 글입니다. (This is an article about the problem of "LCS" in Baekjoon<br />
 Number 9251)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9251%eb%b2%88-lcs-c-baekjoon/34481/">백준 9251번 (LCS, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-8a34d67c      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#lcs" class="uagb-toc-link__trigger">LCS</a><li class="uagb-toc__list"><a href="#추가-반례" class="uagb-toc-link__trigger">추가 반례</a><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ol>					</div>
									</div>
				</div>
			


<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">LCS</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/9251" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/9251</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">0.1 초 (<a href="https://www.acmicpc.net/problem/9251#" target="_blank" rel="noreferrer noopener">하단 참고</a>)</td><td class="has-text-align-left" data-align="left">256 MB</td><td class="has-text-align-left" data-align="left">69404</td><td class="has-text-align-left" data-align="left">28234</td><td class="has-text-align-left" data-align="left">20700</td><td class="has-text-align-left" data-align="left">40.213%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size">LCS(Longest Common Subsequence, 최장 공통 부분 수열)문제는 두 수열이 주어졌을 때, </p>



<p class="has-medium-font-size">모두의 부분 수열이 되는 수열 중 가장 긴 것을 찾는 문제이다.</p>



<p class="has-medium-font-size">예를 들어, ACAYKP와 CAPCAK의 LCS는 ACAK가 된다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size">첫째 줄과 둘째 줄에 두 문자열이 주어진다. </p>



<p class="has-medium-font-size">문자열은 알파벳 대문자로만 이루어져 있으며, 최대 1000글자로 이루어져 있다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size">첫째 줄에 입력으로 주어진 두 문자열의 LCS의 길이를 출력한다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">ACAYKP
CAPCAK</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">추가 반례</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/board/search/all/problem/9251/84485" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/board/search/all/problem/9251/84485</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">ACAA
AAACBA</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">3</pre>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 B</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">ABCDEFG
BCDEFGA</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 B</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">6</pre>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 C</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAXAAAAAAAAAAA</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 C</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">999</pre>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 D</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">A
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 D</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1</pre>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<ul class="wp-block-list">
<li>문제를 만든 사람: <a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/bang627" target="_blank" rel="noreferrer noopener">bang627</a>, <a href="https://www.acmicpc.net/user/eric00513" target="_blank" rel="noreferrer noopener">eric00513</a>, <a href="https://www.acmicpc.net/user/qpwoeiruty" target="_blank" rel="noreferrer noopener">qpwoeiruty</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/25" target="_blank" rel="noreferrer noopener">다이나믹 프로그래밍</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/158" target="_blank" rel="noreferrer noopener">문자열</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<h1 class="wp-block-heading">통과된 코드</h1>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="756" height="1920" src="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230509_065443079.jpg" alt="" class="wp-image-34490" srcset="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230509_065443079.jpg 756w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230509_065443079-118x300.jpg 118w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230509_065443079-605x1536.jpg 605w" sizes="(max-width: 756px) 100vw, 756px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>

using namespace std;

string _StrA, _StrB, _TempStr;
int _Res, _DP[1001];

int main()
{
	cin >> _StrA >> _StrB;

	int _Max = max(_StrA.size(), _StrB.size());

	for (int i = 0; i &lt; _StrB.length(); i++) {
		int _Temp = 0;
		for (int j = 0; j &lt; _StrA.length(); j++) {
			if (_Temp &lt; _DP[j]) 
				_Temp = _DP[j];
			else if (_StrB[i] == _StrA[j]) 
				_DP[j] = _Temp + 1;
		}
	}

	for (int i = 0; i &lt; _Max; i++)
		_Res = max(_DP[i], _Res);

	cout &lt;&lt; _Res;

	return 0;
}</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/05/image-12.png" alt="" class="wp-image-34482" width="947" height="129" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-12.png 827w, https://lycos7560.com/wp-content/uploads/2023/05/image-12-300x41.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-12-768x105.png 768w" sizes="(max-width: 947px) 100vw, 947px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9251%eb%b2%88-lcs-c-baekjoon/34481/">백준 9251번 (LCS, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9251%eb%b2%88-lcs-c-baekjoon/34481/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
