Algorithm/Baekjoon 30

[백준] 14889 스타트와 링크 파이썬 python

문제링크 https://www.acmicpc.net/problem/14889 14889번: 스타트와 링크 예제 2의 경우에 (1, 3, 6), (2, 4, 5)로 팀을 나누면 되고, 예제 3의 경우에는 (1, 2, 4, 5), (3, 6, 7, 8)로 팀을 나누면 된다. www.acmicpc.net 코드 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 import sys input = sys.stdin.readline n = int(i..

Algorithm/Baekjoon 2022.02.25

[백준] 6603 로또 파이썬 python

문제링크 https://www.acmicpc.net/problem/6603 6603번: 로또 입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있다. 첫 번째 수는 k (6 < k < 13)이고, 다음 k개 수는 집합 S에 포함되는 수이다. S의 원소는 오름차순으로 www.acmicpc.net 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import sys input = sys.stdin.readline def bf(cnt,start, case,tmp): if cnt == 6: print(*tmp) return else: for i in range(start,len(case)): if case[i] not..

Algorithm/Baekjoon 2022.02.24

[백준] 10971 외판원 순회2 파이썬 python

문제링크 https://www.acmicpc.net/problem/10971 10971번: 외판원 순회 2 첫째 줄에 도시의 수 N이 주어진다. (2 ≤ N ≤ 10) 다음 N개의 줄에는 비용 행렬이 주어진다. 각 행렬의 성분은 1,000,000 이하의 양의 정수이며, 갈 수 없는 경우는 0이 주어진다. W[i][j]는 도시 i에서 j www.acmicpc.net 코드 풀이1 itertools.permutations 사용 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 import sys from itertools import permutations input = sys.stdin.readline INF = 10*..

Algorithm/Baekjoon 2022.02.23

[백준] 10819 차이를 최대 파이썬 python

문제링크 https://www.acmicpc.net/problem/10819 10819번: 차이를 최대로 첫째 줄에 N (3 ≤ N ≤ 8)이 주어진다. 둘째 줄에는 배열 A에 들어있는 정수가 주어진다. 배열에 들어있는 정수는 -100보다 크거나 같고, 100보다 작거나 같다. www.acmicpc.net 코드 방법1 permutations사용 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import sys from itertools import permutations input = sys.stdin.readline n = int(input()) a = list(map(int,input().split())) all = permutations(a) ans = 0 for ..

Algorithm/Baekjoon 2022.02.22

[백준] 10974 모든 순열 파이썬 python

문제링크 https://www.acmicpc.net/problem/10974 10974번: 모든 순열 N이 주어졌을 때, 1부터 N까지의 수로 이루어진 순열을 사전순으로 출력하는 프로그램을 작성하시오. www.acmicpc.net 코드 방법1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import sys input = sys.stdin.readline n = int(input()) a = list(range(1,n+1)) def bf(arr,cur): if arr: for i in range(n-len(cur)): temp = list(cur) temp.append(arr[i]) new_arr = arr[:i]+arr[i+1:] bf(new_arr,temp) else..

Algorithm/Baekjoon 2022.02.22

[백준] 10973 이전 순열 파이썬 python

문제링크 https://www.acmicpc.net/problem/10973 10973번: 이전 순열 첫째 줄에 입력으로 주어진 순열의 이전에 오는 순열을 출력한다. 만약, 사전순으로 가장 처음에 오는 순열인 경우에는 -1을 출력한다. www.acmicpc.net 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) for i in range(n-1, 0, -1): if a[i-1]>a[i]: target = i-1 break else: print(-1) sys.exit() for i in ..

Algorithm/Baekjoon 2022.02.20

[백준] 10972 다음 순열 파이썬 python

문제링크 https://www.acmicpc.net/problem/10972 10972번: 다음 순열 첫째 줄에 입력으로 주어진 순열의 다음에 오는 순열을 출력한다. 만약, 사전순으로 마지막에 오는 순열인 경우에는 -1을 출력한다. www.acmicpc.net 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) for i in range(n-1, 0, -1): if a[i-1]> [1,4,2,3,5] 완성!!!! 파이썬 Asterisk * 용도 1) 곱셈, 거듭제곱 2) 가변 인자 *args(posi..

Algorithm/Baekjoon 2022.02.20

[백준] 1309 동물원 파이썬 python

문제링크 https://www.acmicpc.net/problem/1309 1309번: 동물원 첫째 줄에 우리의 크기 N(1≤N≤100,000)이 주어진다. www.acmicpc.net 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import sys input = sys.stdin.readline n = int(input()) d = [[0]*3 for _ in range(n+1)] d[1] = [1,1,1] for i in range(2,n+1): for j in range(3): if j ==0: d[i][j] = sum(d[i-1])%9901 elif j==1: d[i][j] = (d[i-1][0]+d[i-1][2])%9901 else: d[i][j] = (..

Algorithm/Baekjoon 2022.02.19

[백준] 1149 RGB거리 파이썬 python

문제링크 https://www.acmicpc.net/problem/1149 1149번: RGB거리 첫째 줄에 집의 수 N(2 ≤ N ≤ 1,000)이 주어진다. 둘째 줄부터 N개의 줄에는 각 집을 빨강, 초록, 파랑으로 칠하는 비용이 1번 집부터 한 줄에 하나씩 주어진다. 집을 칠하는 비용은 1,000보다 작거나 www.acmicpc.net 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import sys input = sys.stdin.readline n = int(input()) d = [list(map(int,input().split())) for _ in range(n)] for i in range(1,n): for j in range(3): if j ==0..

Algorithm/Baekjoon 2022.02.18

[백준] 15988 1,2,3 더하기 3 파이썬 python

문제링크 https://www.acmicpc.net/problem/15988 15988번: 1, 2, 3 더하기 3 각 테스트 케이스마다, n을 1, 2, 3의 합으로 나타내는 방법의 수를 1,000,000,009로 나눈 나머지를 출력한다. www.acmicpc.net 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import sys input = sys.stdin.readline d = [0] *1000001 d[1] = 1 d[2] = 2 d[3] = 4 t = int(input()) ns = [] for _ in range(t): ns.append(int(input())) k = max(ns) for i in range(4,k+1): d[i] = (..

Algorithm/Baekjoon 2022.02.17