N, M = map(int, input().split())

num_list = [i + 1 for i in range(N)]
check_list = [False] * N

arr = []

def dfs(cnt):
    if(cnt == M):
        print(*arr)
        return
    
    for i in range(0, N):
        if(check_list[i]):
            continue
            
        arr.append(num_list[i])
        dfs(cnt + 1)
        check_list[i] = True
        arr.pop()
        
        for j in range(i + 1, N):
            check_list[j] = False
        
dfs(0)

'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글

백준 2580번(python)  (0) 2020.01.01
백준 9963번(python)  (0) 2019.12.31
백준 15651번(python)  (6) 2019.12.31
백준 15650번(python)  (0) 2019.12.31
백준 15649번(python)  (1) 2019.12.31


N, M = map(int, input().split())

num_list = [i + 1 for i in range(N)]
check_list = [False] * N

arr = []

def dfs(cnt):
	# 주어진 만큼 출력한다.
    if(cnt == M):
        print(*arr)
        return
    
    for i in range(0, N):
        if(check_list[i]):
            continue
        arr.append(num_list[i])
        
        dfs(cnt + 1)
        check_list[i] = True
        arr.pop()
        
        for j in range(0, N):
            check_list[j] = False
        
dfs(0)

 

'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글

백준 9963번(python)  (0) 2019.12.31
백준 15652번(python)  (0) 2019.12.31
백준 15650번(python)  (0) 2019.12.31
백준 15649번(python)  (1) 2019.12.31
백준 1912번(python)  (0) 2019.08.20


N, M = map(int, input().split())

num_list = [i + 1 for i in range(N)]
check_list = [False] * N

arr = []

def dfs(cnt):
    if(cnt == M):
        print(*arr)
        return
    
    for i in range(0, N):
        if(check_list[i]):
            continue
        
        check_list[i] = True
        arr.append(num_list[i])
        dfs(cnt + 1)
        arr.pop()
        
        # 이 부분이 순열하고의 차이점이다.
        # 큰 나무에서 전에 봤던 것만
        # 닫아주면 된다.
        for j in range(i + 1, N):
            check_list[j] = False
            
        
dfs(0)

https://hwiyong.tistory.com/300?category=844316

(순열)

 

백준 15649번(python)

N, M = map(int, input().split()) num_list = [i + 1 for i in range(N)] check_list = [False] * N arr = [] def dfs(cnt): # 주어진 개수만큼 채워지면 출력한다 if(cnt == M): print(*arr) return for i in r..

hwiyong.tistory.com

 

'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글

백준 15652번(python)  (0) 2019.12.31
백준 15651번(python)  (6) 2019.12.31
백준 15649번(python)  (1) 2019.12.31
백준 1912번(python)  (0) 2019.08.20
백준 9251번(python)  (0) 2019.08.20

N, M = map(int, input().split())

num_list = [i + 1 for i in range(N)]
check_list = [False] * N

arr = []

def dfs(cnt):
    # 주어진 개수만큼 채워지면 출력한다
    if(cnt == M):
        print(*arr)
        return
    
    for i in range(0, N):
        if(check_list[i]):
            continue
        
        # i번째는 거쳐갈거라서 True로 바꾼다.
        check_list[i] = True
        arr.append(num_list[i])
        # 현재의 i를 기준으로 가지치기 시작
        dfs(cnt + 1)
        # 이 부분은
        arr.pop()
        # 여기서 print(arr)을 해보면 작동원리를 알 수 있다.
#         print(arr)
#         print(check_list)
        check_list[i] = False
        
dfs(0)

'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글

백준 15651번(python)  (6) 2019.12.31
백준 15650번(python)  (0) 2019.12.31
백준 1912번(python)  (0) 2019.08.20
백준 9251번(python)  (0) 2019.08.20
백준 2565번(python)  (0) 2019.08.19


# 메모리 초과 코드
N = int(input())
num_list = list(map(int, input().split()))

dp = [[0] * (N) for _ in range(N + 1)]

for i in range(1, N):
    for j in range(i, N):
        dp[i][j] = max(num_list[j - 1] + num_list[j], dp[i][j - 1] + num_list[j])
        
max_value = -1001

for sub_dp in dp:
    if(max_value < max(sub_dp)):
        max_value = max(sub_dp)
print(max_value)
N = int(input())
num_list = list(map(int, input().split()))

dp = [0 for _ in range(N)]
dp[0] = num_list[0]
for i in range(1, N):
    # 위 코드는 첫 번째 경우는 논리에 맞지 않음.
    # case_1 : 현재 인덱스의 수 -> 반례 2, (-2, -1)
    # case_2 : 이전까지의 연속합과 현재 값을 더한 것
    dp[i] = max(num_list[i], dp[i - 1] + num_list[i])
        
print(max(dp))

 

'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글

백준 15650번(python)  (0) 2019.12.31
백준 15649번(python)  (1) 2019.12.31
백준 9251번(python)  (0) 2019.08.20
백준 2565번(python)  (0) 2019.08.19
백준 11054번(python)  (0) 2019.08.18