Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Codeforces Round #802 (Div. 2)
- 코딩테스트
- GROUP BY 절
- level1
- 개념
- 명품 자바 프로그래밍
- BOJ
- JAVA 11
- HAVING 절
- 기초
- 기초100제
- pypy3
- java
- 기본
- SELECT 절
- 응용
- Python
- 헤드퍼스트 디자인패턴
- SQLD / SQLP
- 공공데이터
- 백준
- 단계별로 풀어보기
- programmers
- Codeup
- Java11
- 이론
- baekjoon
- 파이썬
- 자바
- Python 3
Archives
- Today
- Total
Development Project
[ Baekjoon - 단계별로 풀어보기(06/19~) ] - 15단계 : 백트래킹 본문
- 15649 : N과 M(1)
def solve(depth, N, M):
if depth==M:
print(' '.join(map(str,out)))
return
else:
for i in range(len(visited)):
if not visited[i]:
visited[i]=True
out.append(i+1)
solve(depth+1,N,M)
visited[i]=False
out.pop()
N,M=map(int,input().split())
visited=[False]*N
out=[]
solve(0,N,M)
- 15650 : N과 M(2)
N,M=map(int,input().split())
out=[]
def solve(start):
if len(out)==M:
print(' '.join(map(str,out)))
return
for i in range(start, N+1):
if i not in out:
out.append(i)
solve(i+1)
out.pop()
solve(1)
- 15651 : N과 M(3)
N,M=map(int,input().split())
out=[]
def solve(start):
if len(out)==M:
print(' '.join(map(str,out)))
return
for i in range(1,N+1):
out.append(i)
solve(i+1)
out.pop()
solve(1)
- 15652 : N과 M(4)
N,M=map(int,input().split())
out=[]
def solve(start):
if len(out)==M:
print(' '.join(map(str,out)))
return
for i in range(1,N+1):
if len(out)>0:
if out[len(out)-1]>i:
continue
out.append(i)
solve(i+1)
out.pop()
solve(1)
- 9663 : N-Queen => 꼭 Pypy3로 제출하기 (Python3은...무리에요)
import sys
N=int(sys.stdin.readline())
row = [0] * N
res = 0
def is_exist(x):
for i in range(x):
if row[x] == row[i] or abs(row[x] - row[i]) == x-i:
return False
return True
def dfs(x):
global res
if x == N:
res += 1
else:
for i in range(N):
row[x] = i
if is_exist(x):
dfs(x+1)
dfs(0)
print(res)
- 2580 : 스도쿠
'CodingTest > Baekjoon' 카테고리의 다른 글
[ Baekjoon - 09/14 ] - 2738번: 행렬덧셈 (0) | 2022.09.14 |
---|---|
[ Baekjoon - 09/13 ] - 16439번: 치킨치킨치킨 (0) | 2022.09.13 |
[ Baekjoon - 단계별로 풀어보기(06/11~06/13) ] - 14단계 : 정수론 및 조합론 (0) | 2022.06.11 |
[ Baekjoon - 단계별로 풀어보기(06/09~06/10) ] - 13단계 : 기하1 (0) | 2022.06.09 |
[ Baekjoon - 단계별로 풀어보기(06/06~06/08) ] - 12단계 : 집합과 맵 (0) | 2022.06.06 |
Comments