<?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>다이나믹 프로그래밍 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/%EB%8B%A4%EC%9D%B4%EB%82%98%EB%AF%B9-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Fri, 15 Mar 2024 15:57:18 +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>다이나믹 프로그래밍 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<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 fetchpriority="high" 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>백준 2096번 (내려가기, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2096%eb%b2%88-%eb%82%b4%eb%a0%a4%ea%b0%80%ea%b8%b0-c-baekjoon/34960/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2096%eb%b2%88-%eb%82%b4%eb%a0%a4%ea%b0%80%ea%b8%b0-c-baekjoon/34960/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 23 May 2023 03:17:47 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2096]]></category>
		<category><![CDATA[2096번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></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[백준 2096]]></category>
		<category><![CDATA[백준 2096번]]></category>
		<category><![CDATA[슬라이딩 윈도우]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34960</guid>

					<description><![CDATA[<p>백준 2096번 '내려가기' 문제에 대한 글입니다. (This article is about Baekjoon Number 2096 'Going down'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2096%eb%b2%88-%eb%82%b4%eb%a0%a4%ea%b0%80%ea%b8%b0-c-baekjoon/34960/">백준 2096번 (내려가기, 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-454c1bed      "
					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><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">내려가기</h1>



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



<div style="height:62px" 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">4 MB (<a href="https://www.acmicpc.net/problem/2096#">하단 참고</a>)</td><td class="has-text-align-left" data-align="left">33888</td><td class="has-text-align-left" data-align="left">12906</td><td class="has-text-align-left" data-align="left">10056</td><td class="has-text-align-left" data-align="left">36.627%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">N줄에 0 이상 9 이하의 숫자가 세 개씩 적혀 있다. </p>



<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">바로 아래의 수로 넘어가거나, 아니면 바로 아래의 수와 붙어 있는 수로만 이동할 수 있다는 것이다. </p>



<p class="has-medium-font-size">이 제약 조건을 그림으로 나타내어 보면 다음과 같다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1224" height="179" src="https://lycos7560.com/wp-content/uploads/2023/05/image-119.png" alt="" class="wp-image-34961" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-119.png 1224w, https://lycos7560.com/wp-content/uploads/2023/05/image-119-300x44.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-119-768x112.png 768w" sizes="(max-width: 1224px) 100vw, 1224px" /></figure>



<div style="height:20px" 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">점수는 원룡이가 위치한 곳의 수의 합이다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 N(1 ≤ N ≤ 100,000)이 주어진다. </p>



<p class="has-medium-font-size">다음 N개의 줄에는 숫자가 세 개씩 주어진다. </p>



<p class="has-medium-font-size">숫자는 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 중의 하나가 된다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 얻을 수 있는 최대 점수와 최소 점수를 띄어서 출력한다.</p>



<div style="height:62px" 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
1 2 3
4 5 6
4 9 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="">18 6</pre>



<div style="height:40px" 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
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="">0 0</pre>



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



<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/user/dreamian" target="_blank" rel="noreferrer noopener">dreamian</a></li>



<li>잘못된 데이터를 찾은 사람: <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>



<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/68" 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 is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230523_121808487.jpg" alt="" class="wp-image-34965" width="1200" height="1100" srcset="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230523_121808487.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230523_121808487-300x275.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230523_121808487-768x704.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230523_121808487-1536x1407.jpg 1536w" 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;
int _N, _DP[9], _Temp[3];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> _N >> _DP[0] >> _DP[1] >> _DP[2];
	_DP[3] = _DP[0]; // 최솟값 DP 초기화
	_DP[4] = _DP[1];
	_DP[5] = _DP[2];
	for (int i = 1; i &lt; _N; i++) {
		cin >> _DP[6] >> _DP[7] >> _DP[8];
		_Temp[0] = _DP[0];
		_Temp[1] = _DP[1];
		_Temp[2] = _DP[2];
		_DP[0] = max(_Temp[0], _Temp[1]) + _DP[6];
		_DP[1] = max(_Temp[0], max(_Temp[1], _Temp[2])) + _DP[7];
		_DP[2] = max(_Temp[1], _Temp[2]) + _DP[8];
		_Temp[0] = _DP[3];
		_Temp[1] = _DP[4];
		_Temp[2] = _DP[5];
		_DP[3] = min(_Temp[0], _Temp[1]) + _DP[6];
		_DP[4] = min(_Temp[0], min(_Temp[1], _Temp[2])) + _DP[7];
		_DP[5] = min(_Temp[1], _Temp[2]) + _DP[8];
	}

	cout &lt;&lt; max(_DP[0], max(_DP[1], _DP[2])) &lt;&lt; " " &lt;&lt; min(_DP[3], min(_DP[4], _DP[5]));
	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="1207" height="139" src="https://lycos7560.com/wp-content/uploads/2023/05/image-120.png" alt="" class="wp-image-34962" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-120.png 1207w, https://lycos7560.com/wp-content/uploads/2023/05/image-120-300x35.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-120-768x88.png 768w" sizes="(max-width: 1207px) 100vw, 1207px" /></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-2096%eb%b2%88-%eb%82%b4%eb%a0%a4%ea%b0%80%ea%b8%b0-c-baekjoon/34960/">백준 2096번 (내려가기, 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-2096%eb%b2%88-%eb%82%b4%eb%a0%a4%ea%b0%80%ea%b8%b0-c-baekjoon/34960/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>
		<item>
		<title>백준 11660번 (구간 합 구하기 5, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11660%eb%b2%88-%ea%b5%ac%ea%b0%84-%ed%95%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-5-c-baekjoon/34291/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11660%eb%b2%88-%ea%b5%ac%ea%b0%84-%ed%95%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-5-c-baekjoon/34291/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 04 Apr 2023 10:50:02 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[11660]]></category>
		<category><![CDATA[11660번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구간 합 구하기 5]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 11660]]></category>
		<category><![CDATA[백준 11660번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34291</guid>

					<description><![CDATA[<p>백준 11660번 '구간 합 구하기 5' 문제에 대한 글입니다. 다이나믹 프로그래밍 알고리즘을 이용하여 해결하였습니다. (This article is about Baekjoon Number 11660 question of 'Total Section 5'. 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-11660%eb%b2%88-%ea%b5%ac%ea%b0%84-%ed%95%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-5-c-baekjoon/34291/">백준 11660번 (구간 합 구하기 5, 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-f1d93989      "
					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><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/11660" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/11660</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">42382</td><td class="has-text-align-left" data-align="left">19664</td><td class="has-text-align-left" data-align="left">15131</td><td class="has-text-align-left" data-align="left">45.408%</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개의 수가 N×N 크기의 표에 채워져 있다. </p>



<p class="has-medium-font-size">(x1, y1)부터 (x2, y2)까지 합을 구하는 프로그램을 작성하시오. (x, y)는 x행 y열을 의미한다.</p>



<p class="has-medium-font-size">예를 들어, N = 4이고, 표가 아래와 같이 채워져 있는 경우를 살펴보자.</p>



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



<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><td>1</td><td>2</td><td>3</td><td>4</td></tr><tr><td>2</td><td>3</td><td>4</td><td>5</td></tr><tr><td>3</td><td>4</td><td>5</td><td>6</td></tr><tr><td>4</td><td>5</td><td>6</td><td>7</td></tr></tbody></table></figure>



<p class="has-medium-font-size">여기서 (2, 2)부터 (3, 4)까지 합을 구하면 3+4+5+4+5+6 = 27이고, (4, 4)부터 (4, 4)까지 합을 구하면 7이다.</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>



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



<p class="has-medium-font-size">첫째 줄에 표의 크기 N과 합을 구해야 하는 횟수 M이 주어진다. </p>



<p class="has-medium-font-size">(1 ≤ N ≤ 1024, 1 ≤ M ≤ 100,000) 둘째 줄부터 N개의 줄에는 표에 채워져 있는 수가 1행부터 차례대로 주어진다. </p>



<p class="has-medium-font-size">다음 M개의 줄에는 네 개의 정수 x1, y1, x2, y2 가 주어지며, (x1, y1)부터 (x2, y2)의 합을 구해 출력해야 한다. </p>



<p class="has-medium-font-size">표에 채워져 있는 수는 1,000보다 작거나 같은 자연수이다. (x1 ≤ x2, y1 ≤ y2)</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">총 M줄에 걸쳐 (x1, y1)부터 (x2, y2)까지 합을 구해 출력한다.</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="">4 3
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7
2 2 3 4
3 4 3 4
1 1 4 4</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="">27
6
64</pre>



<div style="height:60px" 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="">2 4
1 2
3 4
1 1 1 1
1 2 1 2
2 1 2 1
2 2 2 2</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="">1
2
3
4</pre>



<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/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>어색한 표현을 찾은 사람: <a href="https://www.acmicpc.net/user/f52985" target="_blank" rel="noreferrer noopener">f52985</a></li>



<li>빠진 조건을 찾은 사람: <a href="https://www.acmicpc.net/user/kyma123" target="_blank" rel="noreferrer noopener">kyma123</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>



<li><a href="https://www.acmicpc.net/problem/tag/139" 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 is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/04/image-6.png" alt="" class="wp-image-34295" width="927" height="524" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-6.png 888w, https://lycos7560.com/wp-content/uploads/2023/04/image-6-300x170.png 300w, https://lycos7560.com/wp-content/uploads/2023/04/image-6-768x434.png 768w" sizes="(max-width: 927px) 100vw, 927px" /></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">N과 M의 범위를 보고 시간 초과를 받을 것 같다고 예상은 했지만 일단 구현해보았다. </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>
#include &lt;vector>
#include &lt;tuple>

using namespace std;

int _N, _M, _Res, _Map[1025][1025];

vector&lt;tuple &lt;int, int, int, int>> _QuiryVector;
tuple &lt;int, int, int, int> _Quiry;

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> _N >> _M;
	for (int i = 1; i &lt;= _N; i++) {
		for (int j = 1; j &lt;= _N; j++)  
			cin >> _Map[i][j];	
	}

	for (int i = 0; i &lt; _M; i++) {
		int _X1, _Y1, _X2, _Y2;
		cin >> _X1 >> _Y1 >> _X2 >> _Y2;
		_QuiryVector.push_back(make_tuple(_X1, _Y1, _X2, _Y2));
	}

	for (auto&amp; it : _QuiryVector) {
		_Res = 0;
		for (int i = get&lt;0>(it); i &lt;= get&lt;2>(it); i++) {
			for (int j = get&lt;1>(it); j &lt;= get&lt;3>(it); j++) {
				_Res += _Map[i][j];
			}
		}
		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="1038" height="47" src="https://lycos7560.com/wp-content/uploads/2023/04/image-9.png" alt="" class="wp-image-34302" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-9.png 1038w, https://lycos7560.com/wp-content/uploads/2023/04/image-9-300x14.png 300w, https://lycos7560.com/wp-content/uploads/2023/04/image-9-768x35.png 768w" sizes="(max-width: 1038px) 100vw, 1038px" /></figure>



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



<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="1257" height="532" src="https://lycos7560.com/wp-content/uploads/2023/04/image-8.png" alt="" class="wp-image-34300" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-8.png 1257w, https://lycos7560.com/wp-content/uploads/2023/04/image-8-300x127.png 300w, https://lycos7560.com/wp-content/uploads/2023/04/image-8-768x325.png 768w" sizes="(max-width: 1257px) 100vw, 1257px" /></figure>



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



<p class="has-medium-font-size">내가 생각한 알고리즘에는 Map을 저장할 필요가 없어서 삭제</p>



<div style="height:50px" 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;vector>
#include &lt;tuple>

using namespace std;

int _N, _M, _Res, _RowSum[1025][1025];

int _X1, _Y1, _X2, _Y2;

vector&lt;tuple &lt;int, int, int, int>> _QuiryVector;

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> _N >> _M;

	for (int i = 1; i &lt;= _N; i++) {
		int _Temp = 0;
		for (int j = 1; j &lt;= _N; j++) {
			cin >> _Temp;
			_RowSum[i][j] = _RowSum[i][j - 1] + _Temp;
		}
	}

	for (int i = 0; i &lt; _M; i++) {
		cin >> _X1 >> _Y1 >> _X2 >> _Y2;
		_QuiryVector.push_back(make_tuple(_X1, _Y1, _X2, _Y2));
	}

	for (auto&amp; it : _QuiryVector) {
		_Res = 0;
		for (int i = get&lt;0>(it); i &lt;= get&lt;2>(it); i++) {
			_Res += _RowSum[i][get&lt;3>(it)] - _RowSum[i][get&lt;1>(it) - 1];
		}
		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="1034" height="96" src="https://lycos7560.com/wp-content/uploads/2023/04/image-7.png" alt="" class="wp-image-34297" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-7.png 1034w, https://lycos7560.com/wp-content/uploads/2023/04/image-7-300x28.png 300w, https://lycos7560.com/wp-content/uploads/2023/04/image-7-768x71.png 768w" sizes="(max-width: 1034px) 100vw, 1034px" /></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-11660%eb%b2%88-%ea%b5%ac%ea%b0%84-%ed%95%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-5-c-baekjoon/34291/">백준 11660번 (구간 합 구하기 5, 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-11660%eb%b2%88-%ea%b5%ac%ea%b0%84-%ed%95%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-5-c-baekjoon/34291/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
