<?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>백준 2579 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/%eb%b0%b1%ec%a4%80-2579/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Wed, 22 Feb 2023 23:58:37 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://lycos7560.com/wp-content/uploads/2022/11/cropped-cropped-cropped-log-1-150x150-1-80x80.png</url>
	<title>백준 2579 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>백준 2579번 (계단 오르기, C++, DP) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2579%eb%b2%88-%ea%b3%84%eb%8b%a8-%ec%98%a4%eb%a5%b4%ea%b8%b0-c-dp-baekjoon/5167/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2579%eb%b2%88-%ea%b3%84%eb%8b%a8-%ec%98%a4%eb%a5%b4%ea%b8%b0-c-dp-baekjoon/5167/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 20 Jan 2023 23:06:35 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2579]]></category>
		<category><![CDATA[2579번]]></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[기초]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 2579]]></category>
		<category><![CDATA[백준 2579번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[점화식]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5167</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 2579번 '계단 오르기' 문제에 대한 글입니다. 'DP'를 이용하여 해결하였습니다. (This is BAEKJOON's article on the question of 'climbing stairs' No. 2579. Resolved using 'DP'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2579%eb%b2%88-%ea%b3%84%eb%8b%a8-%ec%98%a4%eb%a5%b4%ea%b8%b0-c-dp-baekjoon/5167/">백준 2579번 (계단 오르기, C++, DP) [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>



<h1 class="wp-block-heading">계단 오르기</h1>



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



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



<figure id="problem-info" 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">143346</td><td class="has-text-align-left" data-align="left">48944</td><td class="has-text-align-left" data-align="left">35360</td><td class="has-text-align-left" data-align="left">33.778%</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 wp-block-paragraph">계단 오르기 게임은 계단 아래 시작점부터 계단 꼭대기에 위치한 도착점까지 가는 게임이다. </p>



<p class="has-medium-font-size wp-block-paragraph">&lt;그림 1>과 같이 각각의 계단에는 일정한 점수가 쓰여 있는데 계단을 밟으면 그 계단에 쓰여 있는 점수를 얻게 된다.</p>



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



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="607" height="410" src="https://lycos7560.com/wp-content/uploads/image-1018.png" alt="" class="wp-image-5168" srcset="https://lycos7560.com/wp-content/uploads/image-1018.png 607w, https://lycos7560.com/wp-content/uploads/image-1018-300x203.png 300w" sizes="(max-width: 607px) 100vw, 607px" /></figure>



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



<p class="has-medium-font-size wp-block-paragraph">예를 들어 &lt;그림 2>와 같이 시작점에서부터 </p>



<p class="has-medium-font-size wp-block-paragraph">첫 번째, 두 번째, 네 번째, 여섯 번째 계단을 밟아 도착점에 도달하면 총 점수는 10 + 20 + 25 + 20 = 75점이 된다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="657" height="428" src="https://lycos7560.com/wp-content/uploads/image-1019.png" alt="" class="wp-image-5169" srcset="https://lycos7560.com/wp-content/uploads/image-1019.png 657w, https://lycos7560.com/wp-content/uploads/image-1019-300x195.png 300w" sizes="(max-width: 657px) 100vw, 657px" /></figure>



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



<p class="has-medium-font-size wp-block-paragraph">계단 오르는 데는 다음과 같은 규칙이 있다.</p>



<p class="has-medium-font-size wp-block-paragraph">1. 계단은 한 번에 한 계단씩 또는 두 계단씩 오를 수 있다. 즉, 한 계단을 밟으면서 이어서 다음 계단이나, 다음 다음 계단으로 오를 수 있다.</p>



<p class="has-medium-font-size wp-block-paragraph">2. 연속된 세 개의 계단을 모두 밟아서는 안 된다. 단, 시작점은 계단에 포함되지 않는다.</p>



<p class="has-medium-font-size wp-block-paragraph">3. 마지막 도착 계단은 반드시 밟아야 한다.</p>



<p class="has-medium-font-size wp-block-paragraph">따라서 첫 번째 계단을 밟고 이어 두 번째 계단이나, 세 번째 계단으로 오를 수 있다. </p>



<p class="has-medium-font-size wp-block-paragraph">하지만, 첫 번째 계단을 밟고 이어 네 번째 계단으로 올라가거나, 첫 번째, 두 번째, 세 번째 계단을 연속해서 모두 밟을 수는 없다.</p>



<p class="has-medium-font-size wp-block-paragraph">각 계단에 쓰여 있는 점수가 주어질 때 이 게임에서 얻을 수 있는 총 점수의 최댓값을 구하는 프로그램을 작성하시오.</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 wp-block-paragraph">입력의 첫째 줄에 계단의 개수가 주어진다.</p>



<p class="has-medium-font-size wp-block-paragraph">둘째 줄부터 한 줄에 하나씩 제일 아래에 놓인 계단부터 순서대로 각 계단에 쓰여 있는 점수가 주어진다. </p>



<p class="has-medium-font-size wp-block-paragraph">계단의 개수는 300이하의 자연수이고, 계단에 쓰여 있는 점수는 10,000이하의 자연수이다.</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 wp-block-paragraph">첫째 줄에 계단 오르기 게임에서 얻을 수 있는 총 점수의 최댓값을 출력한다.</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="">6
10
20
15
25
10
20</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="">75</pre>



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



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



<p class="wp-block-paragraph"><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a> > <a href="https://www.acmicpc.net/category/55" target="_blank" rel="noreferrer noopener">한국정보올림피아드</a> > <a href="https://www.acmicpc.net/category/57" target="_blank" rel="noreferrer noopener">한국정보올림피아드시․도지역본선</a> > <a href="https://www.acmicpc.net/category/70" target="_blank" rel="noreferrer noopener">지역본선 2006</a> > <a href="https://www.acmicpc.net/category/detail/367" target="_blank" rel="noreferrer noopener">초등부</a> 4번</p>



<ul class="wp-block-list">
<li>문제의 오타를 찾은 사람: <a href="https://www.acmicpc.net/user/cjswodmlskfk" target="_blank" rel="noreferrer noopener">cjswodmlskfk</a>, <a href="https://www.acmicpc.net/user/eric00513" target="_blank" rel="noreferrer noopener">eric00513</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>
</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)"/>



<p class="has-medium-font-size wp-block-paragraph">점화식을 찾는데 생각보다 시간을 많이 소모한 문제</p>



<p class="has-medium-font-size wp-block-paragraph">연속된 3개의 계단이 안된다는 조건을 잘 해결해야 쉽게 풀린다.</p>



<p class="has-medium-font-size wp-block-paragraph">arr[N]이 N번째 계단에서의 가장 높은 가치인 경우를 나타낸다.</p>



<p class="has-medium-font-size wp-block-paragraph">=> arr[ ] + arr[ ] 이런 점화식을 만들면 DP 전체가 무너진다. (이런 잘못된 생각으로 시간을 엄청 날렸다.)</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1600" height="1049" src="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230121_074858551.jpg" alt="" class="wp-image-5170" srcset="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230121_074858551.jpg 1600w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230121_074858551-300x197.jpg 300w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230121_074858551-768x504.jpg 768w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230121_074858551-1536x1007.jpg 1536w" sizes="(max-width: 1600px) 100vw, 1600px" /></figure>



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



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



<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;

// N : 계단의 개수
int N;

// value[N] = N번째 계단의 가치
int value[301];

// dp[N] = N번째 계단의 최고 가치
int arr[301];

int main()
{
	cin >> N;

	for (int i = 1; i &lt;= N; i++) cin >> value[i];

	// dp 값 초기화
	arr[0] = 0;
	arr[1] = value[1];
	arr[2] = value[2] + value[1];

	for (int j = 3; j &lt;= N; j++) {
		arr[j] = max(arr[j - 2] + value[j], arr[j - 3] + value[j] + value[j - 1]);
	}

	cout &lt;&lt; arr[N];

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1036" height="101" src="https://lycos7560.com/wp-content/uploads/image-1020.png" alt="" class="wp-image-5173" srcset="https://lycos7560.com/wp-content/uploads/image-1020.png 1036w, https://lycos7560.com/wp-content/uploads/image-1020-300x29.png 300w, https://lycos7560.com/wp-content/uploads/image-1020-768x75.png 768w" sizes="(max-width: 1036px) 100vw, 1036px" /></figure>



<div style="height:60px" 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-2579%eb%b2%88-%ea%b3%84%eb%8b%a8-%ec%98%a4%eb%a5%b4%ea%b8%b0-c-dp-baekjoon/5167/">백준 2579번 (계단 오르기, C++, DP) [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-2579%eb%b2%88-%ea%b3%84%eb%8b%a8-%ec%98%a4%eb%a5%b4%ea%b8%b0-c-dp-baekjoon/5167/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
