<?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%B0%B1%ED%8A%B8%EB%A0%88%ED%82%B9/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Thu, 27 Jul 2023 08:42:44 +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>백준 1799번 (비숍, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1799%eb%b2%88-%eb%b9%84%ec%88%8d-c-baekjoon/36346/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1799%eb%b2%88-%eb%b9%84%ec%88%8d-c-baekjoon/36346/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 27 Jul 2023 08:42:42 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1799]]></category>
		<category><![CDATA[1799번]]></category>
		<category><![CDATA[Backtracking]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1799]]></category>
		<category><![CDATA[백준 1799번]]></category>
		<category><![CDATA[백트레킹]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36346</guid>

					<description><![CDATA[<p>비숍 https://www.acmicpc.net/problem/1799 시간 제한 메모리 제한 제출 정답 맞힌 사람 정답 비율 10 초 128 MB 22527 5606 3885 24.324% 문제 서양 장기인 체스에는 대각선 방향으로 움직일 수 있는 비숍(bishop)이 있다. &#60; 그림 1 >과 같은 정사각형 체스판 위에 B라고 표시된 곳에 비숍이 있을 때 비숍은 대각선 방향으로 움직여 O로 표시된 칸에 있는 다른 말을 [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1799%eb%b2%88-%eb%b9%84%ec%88%8d-c-baekjoon/36346/">백준 1799번 (비숍, 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-5013bcb9      "
					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><li 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/1799" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1799</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">10 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">22527</td><td class="has-text-align-left" data-align="left">5606</td><td class="has-text-align-left" data-align="left">3885</td><td class="has-text-align-left" data-align="left">24.324%</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>서양 장기인 체스에는 대각선 방향으로 움직일 수 있는 비숍(bishop)이 있다. </p>



<p>&lt; 그림 1 >과 같은 정사각형 체스판 위에 B라고 표시된 곳에 비숍이 있을 때 </p>



<p>비숍은 대각선 방향으로 움직여 O로 표시된 칸에 있는 다른 말을 잡을 수 있다.</p>



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



<figure class="wp-block-image size-full is-resized"><img fetchpriority="high" decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/07/image-52.png" alt="" class="wp-image-36347" width="293" height="335" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-52.png 391w, https://lycos7560.com/wp-content/uploads/2023/07/image-52-263x300.png 263w" sizes="(max-width: 293px) 100vw, 293px" /></figure>



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



<p>그런데 체스판 위에는 비숍이 놓일 수 없는 곳이 있다. </p>



<p>&lt; 그림 2 >에서 체스판에 색칠된 부분은 비숍이 놓일 수 없다고 하자. </p>



<p>이와 같은 체스판에 서로가 서로를 잡을 수 없도록 하면서 비숍을 놓는다면 &lt; 그림 3 >과 같이 최대 7개의 비숍을 놓을 수 있다.  </p>



<p>색칠된 부분에는 비숍이 놓일 수 없지만 지나갈 수는 있다.</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/07/image-53.png" alt="" class="wp-image-36352" width="296" height="597" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-53.png 395w, https://lycos7560.com/wp-content/uploads/2023/07/image-53-149x300.png 149w" sizes="(max-width: 296px) 100vw, 296px" /></figure>



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



<p>정사각형 체스판의 한 변에 놓인 칸의 개수를 체스판의 크기라고 한다. </p>



<p>체스판의 크기와 체스판 각 칸에 비숍을 놓을 수 있는지 없는지에 대한 정보가 주어질 때, </p>



<p>서로가 서로를 잡을 수 없는 위치에 놓을 수 있는 비숍의 최대 개수를 구하는 프로그램을 작성하시오.</p>



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



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



<p>첫째 줄에 체스판의 크기가 주어진다. </p>



<p>체스판의 크기는 10이하의 자연수이다. </p>



<p>둘째 줄부터 아래의 예와 같이 체스판의 각 칸에 비숍을 놓을 수 있는지 없는지에 대한 정보가 체스판 한 줄 단위로 한 줄씩 주어진다. </p>



<p>비숍을 놓을 수 있는 곳에는 1, 비숍을 놓을 수 없는 곳에는 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="">5
1 1 0 1 1
0 1 0 0 0
1 0 1 0 1
1 0 0 0 0
1 0 1 1 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="">7</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/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/68" target="_blank" rel="noreferrer noopener">지역본선 2007</a> > <a href="https://www.acmicpc.net/category/detail/361" target="_blank" rel="noreferrer noopener">초등부</a> 5번</p>



<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/5">백트래킹</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>비숍은 같은 색깔의 비숍만 잡을 수 있다.</p>



<p>다른 색에 있는 비숍까지 모든 경우의 수를 고려한다면 시간 초과가 발생</p>



<p>아래의 코드는 재귀적으로 BackTracking을 구현한 코드</p>



<p>N x N 크기의 체스판에서 N개의 퀸을 배치하는 모든 경우를 탐색</p>



<p>각 칸마다 O(N) 시간이 소요되고, N x N 크기의 체스판에 N개의 퀸을 배치하므로 </p>



<p>총 시간 복잡도는 O(N^N) => 시간초과 </p>



<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;
constexpr int _MAX = 10;
int _N, _Res;
bool _Map[_MAX][_MAX];
bool _Dx[19], _Dy[19];

void BackTracking(int _Cnt, int _x)
{
	int _dxy, _sum;
	for (int i = _x; i &lt; _N; i++)
		for (int j = 0; j &lt; _N; j++) {
			if (!_Map[i][j]) continue;
			_dxy = i - j + _N - 1;
			_sum = i + j;
			if (_Dx[_dxy] || _Dy[i + j]) continue;
			_Dx[_dxy] = true;
			_Dy[_sum] = true;
			BackTracking(_Cnt + 1, i);
			_Dx[_dxy] = false;
			_Dy[_sum] = false;
		}

	_Res = max(_Res, _Cnt);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> _N;
	for (int i = 0; i &lt; _N; i++)
		for (int j = 0; j &lt; _N; j++)
			cin >> _Map[i][j];
	BackTracking(0, 0);
	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/07/image-55.png" alt="" class="wp-image-36367" width="1088" height="59" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-55.png 1450w, https://lycos7560.com/wp-content/uploads/2023/07/image-55-300x16.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-55-768x42.png 768w" sizes="(max-width: 1088px) 100vw, 1088px" /></figure>



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



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



<p>아래의 코드는 하얀 칸에 올 수 있는 비숍의 최댓값과  </p>



<p>검은칸에 올 수 있는 비숍의 최댓값을 따로 구한 후 합한 결과를 출력해준다.</p>



<p>비숍을 해당 칸에 놓는 경우 / 안 놓는 경우 => 2가지</p>



<p>N / 2 칸을 N^2으로 탐색하지만 흑/백 2번이므로 => N^2</p>



<p>약 O(2^N^2)의 시간 복잡도를 가진다.</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;
constexpr int _MAX = 10;
int _N, _Res, _ResSum;
bool _Map[_MAX][_MAX];
bool _CheckX[19], _CheckY[19];

void CheckBishop(int _bishopCnt, int _x, bool _isOdd)
{
	int _dxy, _sum;
	for (int i = _x; i &lt; _N; i++)
		for (int j = 0; j &lt; _N; j++) {
			if (!_Map[i][j]) continue;
			_dxy = i - j + _N - 1;
			_sum = i + j;
			if (_CheckX[_dxy] || _CheckY[i + j] || _sum % 2 == _isOdd) continue;
			_CheckX[_dxy] = true;
			_CheckY[_sum] = true;
			CheckBishop(_bishopCnt + 1, i, _isOdd);
			_CheckX[_dxy] = false;
			_CheckY[_sum] = false;
		}

	_Res = max(_Res, _bishopCnt);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> _N;
	for (int i = 0; i &lt; _N; i++)
		for (int j = 0; j &lt; _N; j++)
			cin >> _Map[i][j];
	CheckBishop(0, 0, false);
	_ResSum += _Res;
	_Res = 0;
	CheckBishop(0, 0, true);
	_ResSum += _Res;
	cout &lt;&lt; _ResSum;
	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/07/image-54.png" alt="" class="wp-image-36360" width="1083" height="84" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-54.png 1444w, https://lycos7560.com/wp-content/uploads/2023/07/image-54-300x23.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-54-768x60.png 768w" sizes="(max-width: 1083px) 100vw, 1083px" /></figure>



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



<p>제출된 답 중에서 0ms 도 있다&#8230; 세상에는 괴물이 많다.</p>



<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-1799%eb%b2%88-%eb%b9%84%ec%88%8d-c-baekjoon/36346/">백준 1799번 (비숍, 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-1799%eb%b2%88-%eb%b9%84%ec%88%8d-c-baekjoon/36346/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 9663번 (N-Queen, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9663%eb%b2%88-n-queen-c-baekjoon/34814/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9663%eb%b2%88-n-queen-c-baekjoon/34814/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 19 May 2023 04:37:46 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[<algorithm>]]></category>
		<category><![CDATA[9663]]></category>
		<category><![CDATA[9663번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Backtracking]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[N-Queen]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 9663]]></category>
		<category><![CDATA[백준 9663번]]></category>
		<category><![CDATA[백트레킹]]></category>
		<category><![CDATA[브루트 포스]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34814</guid>

					<description><![CDATA[<p>백준 9663번 'N-Queen' 문제에 대한 글입니다. 백트레킹을 이용하여 해결하였습니다. (This article is about the question of "N-Queen" in Baekjun 9663. It was solved using backtracking.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9663%eb%b2%88-n-queen-c-baekjoon/34814/">백준 9663번 (N-Queen, 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-b04bb7c8      "
					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="#n-queen" class="uagb-toc-link__trigger">N-Queen</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">N-Queen</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/9663" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/9663</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">10 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">91882</td><td class="has-text-align-left" data-align="left">44089</td><td class="has-text-align-left" data-align="left">28607</td><td class="has-text-align-left" data-align="left">46.649%</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-Queen 문제는&nbsp;크기가 N × N인 체스판 위에 퀸 N개를&nbsp;서로 공격할 수 없게 놓는&nbsp;문제이다.</p>



<p class="has-medium-font-size">N이 주어졌을 때, 퀸을 놓는 방법의 수를 구하는 프로그램을 작성하시오.</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 &lt; 15)</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개를 서로 공격할 수 없게 놓는&nbsp;경우의 수를 출력한다.</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="">5 17</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="">2</pre>



<div style="height:40px" 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">baekjoon</a></li>
</ul>



<div style="height:62px" 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/125">브루트포스 알고리즘</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/5">백트래킹</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 has-large-font-size">통과된 코드</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_20230519_111808847.jpg" alt="" class="wp-image-34817" width="1139" height="1440" srcset="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230519_111808847.jpg 1519w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230519_111808847-237x300.jpg 237w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230519_111808847-768x971.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230519_111808847-1215x1536.jpg 1215w" sizes="(max-width: 1139px) 100vw, 1139px" /></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>
#include &lt;cmath>
using namespace std;
constexpr int Max = 15; // 체스판의 최대 
int _N, _Res, _Queen[Max];

bool CheckQueens(int _row)
{
	for (int i = 0; i &lt; _row; i++) {
		// 절대값으로 대각선으로 전부 확인
		if (_Queen[i] == _Queen[_row] || ( abs(_Queen[i] - _Queen[_row]) == abs(i - _row))) {
			return false;
		}
	}
	return true;
}

void BackTracing(int _row) {
	// N번째까지 왔다면 경우의 수 추가
	if (_row == _N) {
		_Res++;
		return; 
	}

	for (int _col = 0; _col &lt; _N; _col++) {
		_Queen[_row] = _col;
		//해당 행이 가능한지 확인한다.
		if (CheckQueens(_row)) 
			BackTracing(_row + 1);
	}
}

int main()
{
	cin >> _N; // 체스판의 크기 입력
	BackTracing(0); // 백트레킹으로 체크
	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-88.png" alt="" class="wp-image-34820" width="904" height="73" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-88.png 1205w, https://lycos7560.com/wp-content/uploads/2023/05/image-88-300x24.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-88-768x62.png 768w" sizes="(max-width: 904px) 100vw, 904px" /></figure>



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



<h1 class="wp-block-heading">더 효율적인 코드</h1>



<p class="has-medium-font-size">DFS 탐색을 이용한 백트레킹</p>



<p class="has-medium-font-size">dy dx를 대각선으로 표현하여 검사</p>



<figure class="wp-block-image size-full"><img decoding="async" width="400" height="396" src="https://lycos7560.com/wp-content/uploads/2023/05/image-90.png" alt="" class="wp-image-34825" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-90.png 400w, https://lycos7560.com/wp-content/uploads/2023/05/image-90-300x297.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-90-150x150.png 150w" sizes="(max-width: 400px) 100vw, 400px" /></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;
constexpr int Max = 15;
int _N, _Res;
// 체스판 
bool MapArr[Max];
//체스판의 대각선을 표현하기위한 변수
//대각선은 2N - 1개 필요
bool dx[29], dy[29];

void BackTracking(int level)
{
	if (level == _N) {
		_Res++;
		return;
	}
	for (int i = 0; i &lt; _N; i++) {
		//현재 열, 왼쪽 대각선 및 오른쪽 대각선에 이미 배치된 여왕이 없는지 확인
		// dx, dy는 체스판의 특정한 위치를 나타내는 변수가 아니다.
		// dx, dy를 이용하여 대각선을 추적하는 것
		// 배열의 각 인덱스는 dx대각선을 나타내며 해당 인덱스의 값은 대각선이 여왕에 의해 점유되는지 여부를 나타냅니다. 
		if (!MapArr[i] &amp;&amp; !dx[i - level + _N] &amp;&amp; !dy[i + level]) {
			
			MapArr[i] = dx[i - level + _N] = dy[i + level] = true;
			BackTracking(level + 1);
			MapArr[i] = dx[i - level + _N] = dy[i + level] = false;
		}
	}
}

int main() {
	_Res = 0;
	cin >> _N;
	BackTracking(0);
	cout &lt;&lt; _Res;
}</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="99" src="https://lycos7560.com/wp-content/uploads/2023/05/image-89.png" alt="" class="wp-image-34821" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-89.png 1038w, https://lycos7560.com/wp-content/uploads/2023/05/image-89-300x29.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-89-768x73.png 768w" sizes="(max-width: 1038px) 100vw, 1038px" /></figure>



<p></p>



<p></p>



<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-9663%eb%b2%88-n-queen-c-baekjoon/34814/">백준 9663번 (N-Queen, 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-9663%eb%b2%88-n-queen-c-baekjoon/34814/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 15666번 (N과 M (12), C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15666%eb%b2%88-n%ea%b3%bc-m-12-c-baekjoon/34467/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15666%eb%b2%88-n%ea%b3%bc-m-12-c-baekjoon/34467/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 08 May 2023 10:19:23 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[15666]]></category>
		<category><![CDATA[15666번]]></category>
		<category><![CDATA[Backtracking]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[N과 M (12)]]></category>
		<category><![CDATA[SET]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 15666]]></category>
		<category><![CDATA[백준 15666번]]></category>
		<category><![CDATA[백트레킹]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34467</guid>

					<description><![CDATA[<p>백준 15666번 'N과 M (12)' 문제에 대한 글입니다. (This is an article on the question "N and M (12)" of Baekjoon  Number 15666.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15666%eb%b2%88-n%ea%b3%bc-m-12-c-baekjoon/34467/">백준 15666번 (N과 M (12), 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-d69170fb      "
					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="#n과-m-12" class="uagb-toc-link__trigger">N과 M (12)</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">N과 M (12)</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/15666" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/15666</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">2 초</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">13754</td><td class="has-text-align-left" data-align="left">10957</td><td class="has-text-align-left" data-align="left">9464</td><td class="has-text-align-left" data-align="left">80.847%</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개의 자연수와 자연수 M이 주어졌을 때, </p>



<p class="has-medium-font-size">아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오.</p>



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



<p>N개의 자연수 중에서 M개를 고른 수열</p>



<p>같은 수를 여러 번 골라도 된다.</p>



<p>고른 수열은 비내림차순이어야 한다.</p>



<p> => 길이가 K인 수열 A가 A<sub>1</sub> ≤ A<sub>2</sub> ≤ &#8230; ≤ A<sub>K-1</sub> ≤ A<sub>K</sub>를 만족하면, 비내림차순이라고 한다.</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과 M이 주어진다. (1 ≤ M ≤ N ≤ 8)</p>



<p class="has-medium-font-size">둘째 줄에 N개의 수가 주어진다. </p>



<p class="has-medium-font-size">입력으로 주어지는 수는 10,000보다 작거나 같은 자연수이다.</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>



<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">예제 입력 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
4 4 2</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="">2
4</pre>



<div style="height:50px" 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 2
9 7 9 1</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 1
1 7
1 9
7 7
7 9
9 9</pre>



<div style="height:50px" 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="">4 4
1 1 2 2</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="">1 1 1 1
1 1 1 2
1 1 2 2
1 2 2 2
2 2 2 2</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/chogahui05" target="_blank" rel="noreferrer noopener">chogahui05</a>, <a href="https://www.acmicpc.net/user/thak00" target="_blank" rel="noreferrer noopener">thak00</a></li>
</ul>



<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/problem/tag/5" 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>



<p class="has-medium-font-size">자료구조 set을 이용하여 숫자의 중복을 제거 및 정렬</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;set>

using namespace std;

int _N, _M, _Temp, _Arr[8], _Num[8];

void RecursiveFunction(int _X, int _Len) 
{
    if (_Len == _M) {
        for (int i = 0; i &lt; _M; i++)
            cout &lt;&lt; _Arr[i] &lt;&lt; " ";
        cout &lt;&lt; "\n";
        return;
    }

    for (int i = _X; i &lt; _N; i++) {
        _Arr[_Len] = _Num[i];
        RecursiveFunction(i, _Len + 1);
    }
    return;
}

int main()
{
    set&lt;int> _MySet;
    cin >> _N >> _M;
    for (int i = 0; i &lt; _N; i++) {
        cin >> _Temp;
        _MySet.insert(_Temp);
    }

    int _Cnt = 0;

    for (auto&amp; iter : _MySet) 
        _Num[_Cnt++] = iter;
    
    _N = _MySet.size();
    RecursiveFunction(0, 0);
    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-10.png" alt="" class="wp-image-34469" width="969" height="96" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-10.png 829w, https://lycos7560.com/wp-content/uploads/2023/05/image-10-300x30.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-10-768x76.png 768w" sizes="(max-width: 969px) 100vw, 969px" /></figure>



<div style="height:50px" 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-15666%eb%b2%88-n%ea%b3%bc-m-12-c-baekjoon/34467/">백준 15666번 (N과 M (12), 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-15666%eb%b2%88-n%ea%b3%bc-m-12-c-baekjoon/34467/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 15657번 (N과 M (8), C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15657%eb%b2%88-n%ea%b3%bc-m-8-c-baekjoon/34430/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15657%eb%b2%88-n%ea%b3%bc-m-8-c-baekjoon/34430/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 07 May 2023 14:26:07 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[15657]]></category>
		<category><![CDATA[15657번]]></category>
		<category><![CDATA[Backtracking]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[N과 M (8)]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 15657]]></category>
		<category><![CDATA[백준 15657번]]></category>
		<category><![CDATA[백트레킹]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34430</guid>

					<description><![CDATA[<p>백준 15657번 'N과 M (8) ' 문제에 대한 글입니다. (This is an article on the issue of "N and M (8)" in Baekjoon Number 15657)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15657%eb%b2%88-n%ea%b3%bc-m-8-c-baekjoon/34430/">백준 15657번 (N과 M (8), 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-e51ad4a7      "
					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="#n과-m-8" class="uagb-toc-link__trigger">N과 M (8)</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">N과 M (8)</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/15657" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/15657</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">512 MB</td><td class="has-text-align-left" data-align="left">18753</td><td class="has-text-align-left" data-align="left">15398</td><td class="has-text-align-left" data-align="left">13140</td><td class="has-text-align-left" data-align="left">82.238%</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개의 자연수와 자연수 M이 주어졌을 때, </p>



<p class="has-medium-font-size">아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오. </p>



<p class="has-medium-font-size">N개의 자연수는 모두 다른 수이다.</p>



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



<p>N개의 자연수 중에서 M개를 고른 수열</p>



<p>같은 수를 여러 번 골라도 된다.</p>



<p>고른 수열은 비내림차순이어야 한다.</p>



<p>  =&gt; 길이가 K인 수열 A가 A<sub>1</sub>&nbsp;≤ A<sub>2</sub>&nbsp;≤ &#8230; ≤ A<sub>K-1</sub>&nbsp;≤ A<sub>K</sub>를 만족하면, 비내림차순이라고 한다.</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과 M이 주어진다. (1 ≤ M ≤ N ≤ 8)</p>



<p class="has-medium-font-size">둘째 줄에 N개의 수가 주어진다. </p>



<p class="has-medium-font-size">입력으로 주어지는 수는 10,000보다 작거나 같은 자연수이다.</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>



<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">예제 입력 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
4 5 2</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="">2
4
5</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 2
9 8 7 1</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 1
1 7
1 8
1 9
7 7
7 8
7 9
8 8
8 9
9 9</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="">4 4
1231 1232 1233 1234</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="">1231 1231 1231 1231
1231 1231 1231 1232
1231 1231 1231 1233
1231 1231 1231 1234
1231 1231 1232 1232
1231 1231 1232 1233
1231 1231 1232 1234
1231 1231 1233 1233
1231 1231 1233 1234
1231 1231 1234 1234
1231 1232 1232 1232
1231 1232 1232 1233
1231 1232 1232 1234
1231 1232 1233 1233
1231 1232 1233 1234
1231 1232 1234 1234
1231 1233 1233 1233
1231 1233 1233 1234
1231 1233 1234 1234
1231 1234 1234 1234
1232 1232 1232 1232
1232 1232 1232 1233
1232 1232 1232 1234
1232 1232 1233 1233
1232 1232 1233 1234
1232 1232 1234 1234
1232 1233 1233 1233
1232 1233 1233 1234
1232 1233 1234 1234
1232 1234 1234 1234
1233 1233 1233 1233
1233 1233 1233 1234
1233 1233 1234 1234
1233 1234 1234 1234
1234 1234 1234 1234</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">baekjoon</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/5">백트래킹</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>



<p>재귀를 이용하여 출력</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;algorithm>
using namespace std;
int _N, _M, _Arr[8], _Num[8];
void RecursiveFunction(int _X, int _Len) {
    if (_Len == _M) {
        for (int i = 0; i &lt; _M; i++) 
            cout &lt;&lt; _Arr[i] &lt;&lt; " ";
        cout &lt;&lt; "\n";
        return;
    }

    for (int i = _X; i &lt; _N; i++) {
        _Arr[_Len] = _Num[i];
        RecursiveFunction(i, _Len + 1);
    }
    return;
}
int main() 
{
    cin >> _N >> _M;
    for (int i = 0; i &lt; _N; i++)
        cin >> _Num[i];
    sort(_Num, _Num + _N); // 정렬
    RecursiveFunction(0, 0);
    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-7.png" alt="" class="wp-image-34436" width="931" height="89" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-7.png 833w, https://lycos7560.com/wp-content/uploads/2023/05/image-7-300x29.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-7-768x74.png 768w" sizes="(max-width: 931px) 100vw, 931px" /></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-15657%eb%b2%88-n%ea%b3%bc-m-8-c-baekjoon/34430/">백준 15657번 (N과 M (8), 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-15657%eb%b2%88-n%ea%b3%bc-m-8-c-baekjoon/34430/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 15650번 (N과 M (2), C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15650%eb%b2%88-n%ea%b3%bc-m-2-c-baekjoon/34440/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15650%eb%b2%88-n%ea%b3%bc-m-2-c-baekjoon/34440/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 02 May 2023 14:43:23 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[15650]]></category>
		<category><![CDATA[15650번]]></category>
		<category><![CDATA[Backtracking]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[N과 M (2)]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 15650]]></category>
		<category><![CDATA[백준 15650번]]></category>
		<category><![CDATA[백트레킹]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34440</guid>

					<description><![CDATA[<p>백준 15650번 'N과 M (2)' 문제에 대한 글입니다. (This is an article on the question "N and M (2)" of Baekjoon Number 15650.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15650%eb%b2%88-n%ea%b3%bc-m-2-c-baekjoon/34440/">백준 15650번 (N과 M (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-a571c40a      "
					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="#n과-m-2" class="uagb-toc-link__trigger">N과 M (2)</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">N과 M (2)</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/15650">https://www.acmicpc.net/problem/15650</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">512 MB</td><td class="has-text-align-left" data-align="left">59534</td><td class="has-text-align-left" data-align="left">44408</td><td class="has-text-align-left" data-align="left">31942</td><td class="has-text-align-left" data-align="left">73.979%</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과 M이 주어졌을 때, </p>



<p class="has-medium-font-size">아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오.</p>



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



<p>1부터 N까지&nbsp;자연수 중에서 중복 없이 M개를 고른 수열</p>



<p>고른 수열은 오름차순이어야 한다.</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과 M이 주어진다. (1 ≤ M ≤ N ≤ 8)</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>



<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">예제 입력 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</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
2
3</pre>



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



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



<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/problem/tag/5" 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>



<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, _Arr[8], _Num[8];

void RecursiveFunction(int _X, int _Len) {
    if (_Len == _M) {
        for (int i = 0; i &lt; _M; i++) 
            cout &lt;&lt; _Arr[i] &lt;&lt; " ";
        cout &lt;&lt; "\n";
        return;
    }

    for (int i = _X; i &lt; _N; i++) {
        _Arr[_Len] = _Num[i];
        RecursiveFunction(i + 1, _Len + 1);
    }
    return;
}

int main() 
{
    cin >> _N >> _M;
    for (int i = 0; i &lt; _N; i++)
        _Num[i] = i + 1;
    RecursiveFunction(0, 0);
    return 0;
}</pre>



<div style="height:50px" 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-8.png" alt="" class="wp-image-34444" width="912" height="85" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-8.png 834w, https://lycos7560.com/wp-content/uploads/2023/05/image-8-300x28.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-8-768x72.png 768w" sizes="(max-width: 912px) 100vw, 912px" /></figure>



<div style="height:62px" 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-15650%eb%b2%88-n%ea%b3%bc-m-2-c-baekjoon/34440/">백준 15650번 (N과 M (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-15650%eb%b2%88-n%ea%b3%bc-m-2-c-baekjoon/34440/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 15654번 (N과 M (5), C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15654%eb%b2%88-n%ea%b3%bc-m-5-c-baekjoon/34460/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15654%eb%b2%88-n%ea%b3%bc-m-5-c-baekjoon/34460/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sat, 29 Apr 2023 16:42:24 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[15654]]></category>
		<category><![CDATA[15654번]]></category>
		<category><![CDATA[Backtracking]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[N과 M (5)]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 15654]]></category>
		<category><![CDATA[백준 15654번]]></category>
		<category><![CDATA[백트레킹]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34460</guid>

					<description><![CDATA[<p>백준 15654번 'N과 M (5)' 문제에 대한 글입니다. (This is an article on the question "N and M (5)" of Baekjoon Number 15654)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15654%eb%b2%88-n%ea%b3%bc-m-5-c-baekjoon/34460/">백준 15654번 (N과 M (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-194d3ee3      "
					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="#n과-m-5" class="uagb-toc-link__trigger">N과 M (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">N과 M (5)</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/15654" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/15654</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">26965</td><td class="has-text-align-left" data-align="left">19753</td><td class="has-text-align-left" data-align="left">15869</td><td class="has-text-align-left" data-align="left">72.797%</td></tr></tbody></table></figure>



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



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



<p>N개의 자연수와 자연수 M이 주어졌을 때, </p>



<p>아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오. </p>



<p>N개의 자연수는 모두 다른 수이다.</p>



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



<p>N개의 자연수 중에서 M개를 고른 수열</p>



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



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



<p>첫째 줄에 N과 M이 주어진다. (1 ≤ M ≤ N ≤ 8)</p>



<p>둘째 줄에 N개의 수가 주어진다. </p>



<p>입력으로 주어지는 수는 10,000보다 작거나 같은 자연수이다.</p>



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



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



<p>한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. </p>



<p>중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다.</p>



<p>수열은 사전 순으로 증가하는 순서로 출력해야 한다.</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 1
4 5 2</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="">2
4
5</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 2
9 8 7 1</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 7
1 8
1 9
7 1
7 8
7 9
8 1
8 7
8 9
9 1
9 7
9 8</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="">4 4
1231 1232 1233 1234</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="">1231 1232 1233 1234
1231 1232 1234 1233
1231 1233 1232 1234
1231 1233 1234 1232
1231 1234 1232 1233
1231 1234 1233 1232
1232 1231 1233 1234
1232 1231 1234 1233
1232 1233 1231 1234
1232 1233 1234 1231
1232 1234 1231 1233
1232 1234 1233 1231
1233 1231 1232 1234
1233 1231 1234 1232
1233 1232 1231 1234
1233 1232 1234 1231
1233 1234 1231 1232
1233 1234 1232 1231
1234 1231 1232 1233
1234 1231 1233 1232
1234 1232 1231 1233
1234 1232 1233 1231
1234 1233 1231 1232
1234 1233 1232 1231</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>
</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/5" 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>



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

using namespace std;

int _N, _M, _Arr[8], _Num[8];
bool _NumBool[8];
void RecursiveFunction(int _X, int _Len) {
    if (_Len == _M) {
        for (int i = 0; i &lt; _M; i++)
            cout &lt;&lt; _Arr[i] &lt;&lt; " ";
        cout &lt;&lt; "\n";
        return;
    }

    for (int i = 0; i &lt; _N; i++) {
        if (_NumBool[i]) continue;
        _Arr[_Len] = _Num[i];
        _NumBool[i] = true;
        RecursiveFunction(i, _Len + 1);
        _NumBool[i] = false;
    }

    return;
}

int main()
{
    cin >> _N >> _M;
    for (int i = 0; i &lt; _N; i++)
        cin >> _Num[i];
    sort(_Num, _Num + _N); // 정렬
    RecursiveFunction(0, 0);
    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="828" height="81" src="https://lycos7560.com/wp-content/uploads/2023/05/image-9.png" alt="" class="wp-image-34462" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-9.png 828w, https://lycos7560.com/wp-content/uploads/2023/05/image-9-300x29.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-9-768x75.png 768w" sizes="(max-width: 828px) 100vw, 828px" /></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-15654%eb%b2%88-n%ea%b3%bc-m-5-c-baekjoon/34460/">백준 15654번 (N과 M (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-15654%eb%b2%88-n%ea%b3%bc-m-5-c-baekjoon/34460/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 15663번 (N과 M (9), C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15663%eb%b2%88-n%ea%b3%bc-m-9-c-baekjoon/34472/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15663%eb%b2%88-n%ea%b3%bc-m-9-c-baekjoon/34472/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 16 Apr 2023 15:48:19 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[15663]]></category>
		<category><![CDATA[15663번]]></category>
		<category><![CDATA[Backtracking]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[N과 M (9)]]></category>
		<category><![CDATA[SET]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 15663]]></category>
		<category><![CDATA[백준 15663번]]></category>
		<category><![CDATA[백트레킹]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34472</guid>

					<description><![CDATA[<p>백준 15663번 'N과 M (9)' 문제에 대한 글입니다. (This is an article on the question of BAEKJOON Number 15663 'N and M (9)')</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15663%eb%b2%88-n%ea%b3%bc-m-9-c-baekjoon/34472/">백준 15663번 (N과 M (9), 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-b0f74a2d      "
					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="#n과-m-9" class="uagb-toc-link__trigger">N과 M (9)</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">N과 M (9)</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/15663" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/15663</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">29219</td><td class="has-text-align-left" data-align="left">14418</td><td class="has-text-align-left" data-align="left">10819</td><td class="has-text-align-left" data-align="left">49.001%</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개의 자연수와 자연수 M이 주어졌을 때, </p>



<p class="has-medium-font-size">아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오.</p>



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



<p>N개의 자연수 중에서 M개를 고른 수열</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이 주어진다. (1 ≤ M ≤ N ≤ 8)</p>



<p class="has-medium-font-size">둘째 줄에 N개의 수가 주어진다. </p>



<p class="has-medium-font-size">입력으로 주어지는 수는 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">한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. </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">예제 입력 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
4 4 2</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="">2
4</pre>



<div style="height:50px" 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 2
9 7 9 1</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 7
1 9
7 1
7 9
9 1
9 7
9 9</pre>



<div style="height:50px" 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="">4 4
1 1 1 1</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="">1 1 1 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>문제를 만든 사람:&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/kid7ho" target="_blank" rel="noreferrer noopener">kid7ho</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/5">백트</a><a href="https://www.acmicpc.net/problem/tag/5" target="_blank" rel="noreferrer noopener">래</a><a href="https://www.acmicpc.net/problem/tag/5">킹</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_20230509_012310585.jpg" alt="" class="wp-image-34479" width="1358" height="1409" srcset="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230509_012310585.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230509_012310585-289x300.jpg 289w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230509_012310585-768x797.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230509_012310585-1480x1536.jpg 1480w" sizes="(max-width: 1358px) 100vw, 1358px" /></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>
#include &lt;algorithm>

using namespace std;

int _N, _M, _Arr[8], _Num[8];
bool _NumBool[8]; // 중복을 확인

void RecursiveFunction(int _Len) 
{
    if (_Len == _M) {
        for (int i = 0; i &lt; _M; i++)
            cout &lt;&lt; _Arr[i] &lt;&lt; " ";
        cout &lt;&lt; "\n";
        return;
    }

    int _Temp = 0;
    for (int i = 0; i &lt; _N; i++) {
        if (!_NumBool[i] &amp;&amp; _Num[i] != _Temp) {
            _Arr[_Len] = _Num[i];
            _Temp = _Arr[_Len];
            _NumBool[i] = true;
            RecursiveFunction(_Len + 1);
            _NumBool[i] = false;    
        }
    }
    return;
}

int main()
{
    cin >> _N >> _M;
    for (int i = 0; i &lt; _N; i++) 
        cin >> _Num[i];
    sort(_Num, _Num + _N);
    RecursiveFunction(0);
    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-11.png" alt="" class="wp-image-34474" width="943" height="173" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-11.png 828w, https://lycos7560.com/wp-content/uploads/2023/05/image-11-300x55.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-11-768x141.png 768w" sizes="(max-width: 943px) 100vw, 943px" /></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-15663%eb%b2%88-n%ea%b3%bc-m-9-c-baekjoon/34472/">백준 15663번 (N과 M (9), 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-15663%eb%b2%88-n%ea%b3%bc-m-9-c-baekjoon/34472/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 15652번 (N과 M (4), C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15652%eb%b2%88-n%ea%b3%bc-m-4-c-baekjoon/34449/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15652%eb%b2%88-n%ea%b3%bc-m-4-c-baekjoon/34449/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 14 Apr 2023 15:00:35 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[15652]]></category>
		<category><![CDATA[15652번]]></category>
		<category><![CDATA[Backtracking]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[N과 M (4)]]></category>
		<category><![CDATA[N과 M (8)]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 15652]]></category>
		<category><![CDATA[백준 15652번]]></category>
		<category><![CDATA[백트레킹]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34449</guid>

					<description><![CDATA[<p>백준 15652번 'N과 M (4)' 문제에 대한 글입니다. (This is an article on the question "N and M (4)" of Baekjoon Number 15652)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-15652%eb%b2%88-n%ea%b3%bc-m-4-c-baekjoon/34449/">백준 15652번 (N과 M (4), 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-114a9fef      "
					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="#n과-m-4" class="uagb-toc-link__trigger">N과 M (4)</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">N과 M (4)</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/15652" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/15652</a></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">아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오.</p>



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



<p>1부터 N까지&nbsp;자연수 중에서 M개를 고른 수열</p>



<p>같은 수를 여러 번 골라도 된다.</p>



<p>고른 수열은 비내림차순이어야 한다.</p>



<p> =&gt; 길이가 K인 수열 A가 A<sub>1</sub>&nbsp;≤ A<sub>2</sub>&nbsp;≤ &#8230; ≤ A<sub>K-1</sub>&nbsp;≤ A<sub>K</sub>를 만족하면, 비내림차순이라고 한다.</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이 주어진다. (1 ≤ M ≤ N ≤ 8)</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">중복되는 수열을 여러 번 출력하면 안되며, </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">예제 입력 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</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
2
3</pre>



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



<div style="height:50px" 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="">3 3</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="">1 1 1
1 1 2
1 1 3
1 2 2
1 2 3
1 3 3
2 2 2
2 2 3
2 3 3
3 3 3</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>문제를 만든 사람:&nbsp;<a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>
</ul>



<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/problem/tag/5" 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>



<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, _Arr[8], _Num[8];

void RecursiveFunction(int _X, int _Len) {
    if (_Len == _M) {
        for (int i = 0; i &lt; _M; i++) 
            cout &lt;&lt; _Arr[i] &lt;&lt; " ";
        cout &lt;&lt; "\n";
        return;
    }

    for (int i = _X; i &lt; _N; i++) {
        _Arr[_Len] = _Num[i];
        RecursiveFunction(i, _Len + 1);
    }
    return;
}

int main() 
{
    cin >> _N >> _M;
    for (int i = 0; i &lt; _N; i++)
        _Num[i] = i + 1;
    RecursiveFunction(0, 0);
    return 0;
}</pre>



<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-15652%eb%b2%88-n%ea%b3%bc-m-4-c-baekjoon/34449/">백준 15652번 (N과 M (4), 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-15652%eb%b2%88-n%ea%b3%bc-m-4-c-baekjoon/34449/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1182번 (부분수열의 합, C++, DFS) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon-1182%eb%b2%88-%eb%b6%80%eb%b6%84%ec%88%98%ec%97%b4%ec%9d%98-%ed%95%a9-c-dfs-%ec%b6%94%ea%b0%80-%eb%b0%98/1192/</link>
					<comments>https://lycos7560.com/cpp/baekjoon-1182%eb%b2%88-%eb%b6%80%eb%b6%84%ec%88%98%ec%97%b4%ec%9d%98-%ed%95%a9-c-dfs-%ec%b6%94%ea%b0%80-%eb%b0%98/1192/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 28 Oct 2022 11:23:04 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[Backtracking]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[dfs]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1182]]></category>
		<category><![CDATA[백준 1182번]]></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.synology.me/?p=527</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1182번 "부분수열의 합" 문제에 대한 글입니다. DFS 탐색을 이용하여 해결하였습니다. (This article is about the question of "sum of partial sequences" in BAEKJOON 1182. Resolved using DFS Search.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon-1182%eb%b2%88-%eb%b6%80%eb%b6%84%ec%88%98%ec%97%b4%ec%9d%98-%ed%95%a9-c-dfs-%ec%b6%94%ea%b0%80-%eb%b0%98/1192/">백준 1182번 (부분수열의 합, C++, DFS) / 추가 반례 [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:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="has-huge-font-size wp-block-heading"><strong>단어 수학</strong></h1>



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



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



<figure id="problem-info" class="wp-block-table is-style-stripes"><table class="has-ast-global-color-8-color has-ast-global-color-6-background-color has-text-color has-background"><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">256 MB</td><td class="has-text-align-left" data-align="left">58135</td><td class="has-text-align-left" data-align="left">26802</td><td class="has-text-align-left" data-align="left">17364</td><td class="has-text-align-left" data-align="left">44.381%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">N개의 정수로 이루어진 수열이 있을 때, 크기가 양수인 부분 수열 중에서 <br>그 수열의 원소를 다 더한 값이 S가 되는 경우의 수를 구하는 프로그램을 작성하시오.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 정수의 개수를 나타내는 N과 정수 S가 주어진다. <br>(1 ≤ N ≤ 20, |S| ≤ 1,000,000) 둘째 줄에 N개의 정수가 빈 칸을 사이에 두고 주어진다. <br>주어지는 정수의 절댓값은 100,000을 넘지 않는다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 합이 S가 되는 부분 수열의 개수를 출력한다.</p>



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



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



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



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="generic" 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="has-medium-font-size wp-block-heading">출처</h2>



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



<li>문제의 오타를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/eric00513" target="_blank" rel="noreferrer noopener">eric00513</a>,&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/rdd6584" target="_blank" rel="noreferrer noopener">rdd6584</a></li>



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



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



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



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/5" target="_blank" rel="noreferrer noopener">백트래킹</a></li>
</ul>



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



<hr class="wp-block-separator has-text-color has-ast-global-color-8-color has-css-opacity has-ast-global-color-8-background-color has-background is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



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



<h2 class="wp-block-heading">추가 예제</h2>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">12 1000000
1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 -1000000
</pre>



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



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



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



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">8 22
10 8 -6 6 0 10 5 3
</pre>



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



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



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



<div style="height:64px" 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; 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:64px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading"><strong>실패 코드</strong> 1</h2>



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



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

using namespace std;

int N, S, result;
// N 정수의 개수  1&lt;= N &lt;=20 
// S 목표값  |S| &lt;= 1,000,000
// result 목표값과 같아지는 부분수열의 개수

#define MAX 20
// 많이 사용할 것 같아 매크로로 뚫어 놓음

int numbers[MAX] = { 0 };
// 수열들 0으로 초기화

struct MyStruct
{
	int sumNumber;
	int sNumbers[MAX];
}temp, temp2;

queue&lt;MyStruct> myQueue;

// 입력 값을 받는 함수
void SettingConditions()
{
	cin >> N >> S;

	for (int i = 0; i &lt; N; i++)
	{
		cin >> numbers[i];
	}
}

void BFS()
{
	temp.sumNumber = 0;
	copy(numbers, numbers + MAX, temp.sNumbers);
	myQueue.push(temp);

	while (!myQueue.empty())
	{
		temp = myQueue.front();
		myQueue.pop();

		for (int i = 0; i &lt; MAX; i++)
		{
			temp2 = temp;

			if (temp2.sNumbers[i] == 0)
			{
				continue;
			}

			int tempNumber = temp.sNumbers[i];
			temp2.sumNumber += temp.sNumbers[i];

			if (temp2.sumNumber == S)
			{
				result++;
			}
			temp2.sNumbers[i] = 0;
			myQueue.push(temp2);
		}
	}
}

int main()
{
	SettingConditions();
	BFS();

	cout &lt;&lt; "결과 : " &lt;&lt; result;
	return 0;
}</pre>



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



<p class="has-medium-font-size">BFS로 접근 </p>



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



<p class="has-medium-font-size">3 6<br>1 2 3 이라면</p>



<p class="has-medium-font-size">123 132<br>213 231<br>312 321</p>



<p class="has-medium-font-size">을 구분하지 못하는 난감한 상황이 발생하였다.</p>



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



<h2 class="wp-block-heading"><strong>실패 코드</strong> 2</h2>



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

using namespace std;

int N, S, result;
// N 정수의 개수  1&lt;= N &lt;=20 
// S 목표값  |S| &lt;= 1,000,000
// result 목표값과 같아지는 부분수열의 개수

#define MAX 20
// 많이 사용할 것 같아 매크로로 뚫어 놓음

int numbers[MAX] = { 0 };
// 수열들 0으로 초기화

int resultarr[MAX];

struct MyStruct
{
	int sumNumber;
	int sNumbers[MAX];
	bool indexCheck[MAX] = {false};
	
}temp, temp2;

queue&lt;MyStruct> myQueue;

// 입력 값을 받는 함수
void SettingConditions()
{
	cin >> N >> S;

	for (int i = 0; i &lt; N; i++)
	{
		cin >> numbers[i];
	}
}

void Test()
{
	for (int i = 0; i &lt; N; i++)
	{
		cout &lt;&lt; numbers[i] &lt;&lt; " ";
	}
	cout &lt;&lt; "\n";
}

void DFS()
{
	Test();

	temp.sumNumber = 0;
	copy(numbers, numbers + N, temp.sNumbers);
	myQueue.push(temp);
	while (!myQueue.empty())
	{
		temp = myQueue.front();
		myQueue.pop();
		

		for (int i = 0; i &lt; N; i++)
		{
			temp2 = temp;
			
			if (temp2.indexCheck[i] == true)
			{
				continue;
			}

			temp2.sumNumber += temp2.sNumbers[i];
			if (temp2.sumNumber == S)
			{
				result++;
				continue;
			}
			temp2.indexCheck[i] = true;
			myQueue.push(temp2);


		}



	}

}

int main()
{
	SettingConditions();
	DFS();

	cout &lt;&lt; result;
	return 0;
}</pre>



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



<p class="has-medium-font-size">Set을 통한 체크 및 방문 처리<br>메모리 부족 시간 초과로 터짐 </p>



<p class="has-medium-font-size">DFS 로 변경</p>



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



<h2 class="wp-block-heading"><strong>성공 코드</strong> <strong>(DFS)</strong></h2>



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



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

using namespace std;

int N, S, result;

// 자주 사용할 것 같아 매크로로 등록 
#define MAX 20

int numbers[MAX];

void SettingCondition()
{
	result = 0;

	cin >> N >> S;

	for (int i = 0; i &lt; N; i++)
	{
		cin >> numbers[i];
	}
}

void DFS(int index, int total)
{
	if (index == N)
	{
		if (total == S)
		{
			result++;
			return;
		}
		//인덱스 마지막에 리턴
		return;
	}

	// 해당 인덱스의 원소를 사용할 때 / 안할 때
	DFS(index + 1, total + numbers[index]);
	DFS(index + 1, total);
}

int main()
{
	// 셋팅
	SettingCondition();
	DFS(0,0);
	
	// S = 0 이면 처음 시작 시 수열의 원소가 없지만 
	// total이 0 이므로 카운트가 하나 올라간다.
	if (S == 0) 
	{
		result--;
	}
	cout  &lt;&lt; result;
	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="936" height="491" src="https://lycos7560.com/wp-content/uploads/image-71.png" alt="" class="wp-image-2291" srcset="https://lycos7560.com/wp-content/uploads/image-71.png 936w, https://lycos7560.com/wp-content/uploads/image-71-300x157.png 300w, https://lycos7560.com/wp-content/uploads/image-71-768x403.png 768w" sizes="(max-width: 936px) 100vw, 936px" /></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-1182%eb%b2%88-%eb%b6%80%eb%b6%84%ec%88%98%ec%97%b4%ec%9d%98-%ed%95%a9-c-dfs-%ec%b6%94%ea%b0%80-%eb%b0%98/1192/">백준 1182번 (부분수열의 합, C++, DFS) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon-1182%eb%b2%88-%eb%b6%80%eb%b6%84%ec%88%98%ec%97%b4%ec%9d%98-%ed%95%a9-c-dfs-%ec%b6%94%ea%b0%80-%eb%b0%98/1192/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
