[백준 바킹독] 0x09 - BFS 토마토(7576)
Introduction
재귀 함수를 연습하기 좋은 문제
백트래킹
https://www.acmicpc.net/workbook/view/2052
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
s = []
def dfs():
if len(s) == m:
print(" ".join(map(str,s)))
return
for i in range(1,n+1):
if i not in s:
s.append(i)
dfs()
s.pop()
dfs()
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
s = []
def dfs():
if len(s) == m:
print(" ".join(map(str,s)))
return
for i in range(1,n+1):
if len(s) == 0 or i > s[-1]:
s.append(i)
dfs()
s.pop()
dfs()
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
s = []
def dfs():
if len(s) == m:
print(" ".join(map(str,s)))
return
for i in range(1,n+1):
# if len(s) == 0 or i > s[-1]:
s.append(i)
dfs()
s.pop()
dfs()
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
s = []
def dfs():
if len(s) == m:
print(" ".join(map(str,s)))
return
for i in range(1,n+1):
if len(s) == 0 or i >= s[-1]:
s.append(i)
dfs()
s.pop()
dfs()
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
lists = list(map(int,input().split()))
lists.sort()
s = []
def dfs():
if len(s) == m:
print(" ".join(map(str,s)))
return
for i in range(n):
if lists[i] not in s:
s.append(lists[i])
dfs()
s.pop()
dfs()
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
lists = list(map(int,input().split()))
lists.sort()
s = []
def dfs():
if len(s) == m:
print(" ".join(map(str,s)))
return
for i in range(n):
if lists[i] not in s:
s.append(lists[i])
dfs()
s.pop()
dfs()
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
lists = list(map(int,input().split()))
lists.sort()
s = []
def dfs():
if len(s) == m:
print(" ".join(map(str,s)))
return
for i in range(n):
if len(s) == 0 or lists[i] > s[-1]:
s.append(lists[i])
dfs()
s.pop()
dfs()
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
lists = list(map(int,input().split()))
lists.sort()
s = []
def dfs():
if len(s) == m:
print(" ".join(map(str,s)))
return
for i in range(n):
if len(s) == 0 or lists[i] > s[-1]:
s.append(lists[i])
dfs()
s.pop()
dfs()
해당 문제에서 list는 정렬되어 있기 때문에 [1,7,9,9] 일 경우, 직전 값을 저장해서 같지 않을 경우만 확인하면 된다.
또한, 방문했던 값은 다시 방문해서는 안 된다. 따라서 visited 변수를 사용하여 방문했던 곳을 저장해야한다.
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
lists = list(map(int,input().split()))
lists.sort()
s = []
visited = [False]*(n)
def dfs():
if len(s) == m:
print(" ".join(map(str,s)))
return
x = 0
for i in range(n):
if visited[i] == False and x != lists[i]:
visited[i] = True
s.append(lists[i])
x = lists[i]
dfs()
s.pop()
visited[i] = False
dfs()
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
lists = list(map(int,input().split()))
lists.sort()
s = []
visited = [False]*(n)
def dfs():
if len(s) == m:
print(" ".join(map(str,s)))
return
x = 0
for i in range(n):
if visited[i] == False and x != lists[i] and (len(s)==0 or lists[i] >= s[-1]):
visited[i] = True
s.append(lists[i])
x = lists[i]
dfs()
s.pop()
visited[i] = False
dfs()
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
lists = list(map(int,input().split()))
lists.sort()
s = []
def dfs():
if len(s) == m:
print(" ".join(map(str,s)))
return
x = 0
for i in range(n):
if x != lists[i]:
s.append(lists[i])
x = lists[i]
dfs()
s.pop()
dfs()
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
lists = list(map(int,input().split()))
lists.sort()
s = []
def dfs():
if len(s) == m:
print(" ".join(map(str,s)))
return
x = 0
for i in range(n):
if x != lists[i] and (len(s) == 0 or lists[i] >= s[-1]):
s.append(lists[i])
x = lists[i]
dfs()
s.pop()
dfs()
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
1167 트리의 지름
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Git 명령어를 사용한 하위 디렉토리 다운로드 Clone 할 로컬 저장소 생성
Introduction
# Fetch the submodule commits into the main repository git remote add submodule_origin git://url/to/submodule/origin git fetch submodule_origin
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Graph
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Spring Project
the page for java
가벼운 Base image를 사용
version: 3.0.0a10
WIDTH
version: 3.0.0a10
#include <iostream> #include <thread> #include <chrono> #include <mutex> #include <atomic> #include <string.h>
version: 3.0.0a10
https://cplusplus.com/reference/future/
Multithreading support was introduced in C++11.
how to costom github blog using jekyll
You’ll find this post in your _posts directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different wa...