Skip to content

Commit

Permalink
[Silver III] Title: N과 M (3), Time: 1792 ms, Memory: 31120 KB -Baekjo…
Browse files Browse the repository at this point in the history
…onHub
  • Loading branch information
hocheol0303 committed Nov 15, 2024
1 parent f15b280 commit c2715db
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 백준/Silver/15651. N과 M (3)/N과 M (3).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sys

def dfs(start):
global m, lst
if len(lst) == m:
print(*lst)
else:
for i in range(1, n+1):
lst.append(i)
dfs(i+1)
lst.pop()

n, m = map(int, sys.stdin.readline().split())
lst = []

dfs(1)
35 changes: 35 additions & 0 deletions 백준/Silver/15651. N과 M (3)/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# [Silver III] N과 M (3) - 15651

[문제 링크](https://www.acmicpc.net/problem/15651)

### 성능 요약

메모리: 31120 KB, 시간: 1792 ms

### 분류

백트래킹

### 제출 일자

2024년 11월 15일 14:06:27

### 문제 설명

<p>자연수 N과 M이 주어졌을 때, 아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오.</p>

<ul>
<li>1부터 N까지 자연수 중에서 M개를 고른 수열</li>
<li>같은 수를 여러 번 골라도 된다.</li>
</ul>

### 입력

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

### 출력

<p>한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다.</p>

<p>수열은 사전 순으로 증가하는 순서로 출력해야 한다.</p>

0 comments on commit c2715db

Please sign in to comment.