목록python (182)
rose_brown
1. 문제https://school.programmers.co.kr/learn/courses/30/lessons/72411 2. 코드python 1from collections import Counterfrom itertools import combinations def solution(orders, course): answer = [] for i in course: all_combs = [] for order in orders: combs = combinations(sorted(order), i) all_combs.extend(combs) counter = Counter(all_combs) if coun..
1. 문제https://school.programmers.co.kr/learn/courses/30/lessons/12907 2. 코드python 1def solution(n, money): mod = 1000000007 dp = [0] * (n+1) dp[0] = 1 for coin in money: for i in range(coin, n+1): dp[i] += dp[i-coin] return dp[n] % 1000000007풀이dp[i]를 금액 i를 만드는 경우의 수로 정의하고, dp[0] = 1로 초기화→ 0원을 만드는 방법은 "아무 동전도 쓰지 않는 방법" 1가지동전 하나씩 반복하며 가능한 금액(i) 갱신각 coin에..
1. 문제https://www.acmicpc.net/problem/1699 2. 코드python 1import sysinput = sys.stdin.readlineN = int(input())dp = [k for k in range(N+1)]for i in range(1, N+1): for j in range(1, i): if j*j > i: break if dp[i] > dp[i-j*j] + 1: dp[i] = dp[i-j*j] + 1print(dp[N])풀이dp에 N까지의 값들을 리스트에 저장제곱의 수 > 현재의 값 → 조기 종료점화식으로 제곱합 계산최종 N의 제곱수 표현하는 최소 개수 출력 3. 메모반복해서 계산해야 함 → DP를..
1. 문제https://www.acmicpc.net/problem/9095 2. 코드python 1import sysinput = sys.stdin.readlineT = int(input())t_list = [int(input()) for i in range(T)]dp = [0] * 11dp[0] = 1dp[1] = 1dp[2] = 2dp[3] = 4for i in range(4, 11): dp[i] = dp[i-1] + dp[i-2] + dp[i-3]for t in t_list: print(dp[t])풀이“n은 양수이며 11보다 작다” 했으니 10까지 저장할 테이블 초기화(dp)0~3까지 봤을 때 [1,2,3]을 사용해서 합의 개수 저장점화식 생성n =1일 때 → 1가지n=2일 때 → 1+1..
1. 문제https://www.acmicpc.net/problem/1032 2. 코드python 1import sysinput = sys.stdin.readlineN = int(input())n_list = [input().strip() for i in range(N)]answer = ''for i in range(len(n_list[0])): char = n_list[0][i] for j in range(N): if n_list[j][i] !=char: char ='?' break answer += charprint(answer)풀이파일개수, 파일 이름을 입력받음검색 결과를 answer(문자열)에 저장해당 자릿수에서 모든 파일의 문자가..

1. 문제https://www.acmicpc.net/problem/10816 2. 코드python 1import sysinput = sys.stdin.readlinen=int(input())N=sorted(map(int,input().split()))m=int(input())M=map(int,input().split())def binary(l,N,start,end): if start>end: return 0 m = (start+end)//2 count=0 if l==N[m]: return N[start:end+1].count(l) elif l풀이이분탐색을 위해 리스트 N 정렬중간값이랑 비교n ! = 중간요소인 경우 → 탐색범위를 절반으로..
1. 문제https://school.programmers.co.kr/learn/courses/30/lessons/140108 2. 코드python 1def solution(s): answer = 0 i = 0 while i 풀이첫 글자를 기준문자 x라고 설정x_count 는 기준문자 x랑 같은 경우에 += 1첫글자랑 다른 경우 other_count에 +=1x_count랑 other_count가 같다면 그 지점을 하나의 문자열로 처리 → 문자열이 분리 되었으나 answer += 14번 과정 반복최종 문자열 개수 출력 3. 메모문제를 잘 이해해야 함(처음에 이해를 못함..ㅋㅋ)핵심은 ‘기준 문자(x)와 다른 문자의 개수를 세면서, 처음으로 두 개수가 같아지는 순간 문자열을 자른다’는 규칙을 ..
1. 문제https://school.programmers.co.kr/learn/courses/30/lessons/150370 2. 코드python 1def to_days(date): year, month, day = map(int, date.split('.')) return year * 12 * 28 + month*28 + daydef solution(today, terms, privacies): answer = [] todays = to_days(today) terms_dict = {} for t in terms: t_type, date = t.split() terms_dict[t_type] = int(date) for i, p in enu..
1. 문제https://school.programmers.co.kr/learn/courses/30/lessons/118666 2. 코드python 1def solution(survey, choices): answer = '' types = {'R':0, 'T':0, 'C':0, 'F':0, 'J':0, 'M':0, 'A':0, 'N':0} for s, c in zip(survey, choices): if c > 4: types[s[1]] += c - 4 elif c 풀이dict 형태로 성격 유형들 count 할 수 있게 생성survey와 choices에 값에 따라 7가지 대답 유형에 맞게 값 추가dict에 있는 값들을 배열로 바꿈지표 번호에 있는 성격 유형..
1. 문제https://school.programmers.co.kr/learn/courses/15008/lessons/121686 2. 코드python 1from heapq import heappush as push, heappop as popdef push_task(waiting, tasks): start, priority, end = pop(tasks) push(waiting, (priority, start, end)) return startdef solution(program): answer = [0 for _ in range(11)] tasks, waiting, curr = [], [], 0 for p in program: push(tasks, ..