전체 글

전체 글

    종이 조각 풀이

    문제 링크: https://www.acmicpc.net/problem/14391 백준 알고리즘 기초 2/2 540에서 4번째 - 14391번 종이 조각을 풀어보았다. 풀이: 비트마스크를 이용해 푸는 문제이다. https://velog.io/@imnotmoon/Python-%EB%B0%B1%EC%A4%80-14391.-%EC%A2%85%EC%9D%B4-%EC%A1%B0%EA%B0%81 를 참고했다. C++ Python n,m=map(int,input().split()) inp=[list(map(int,input())) for i in range(n)] def sol(): res=0 for i in range(1

    부분수열의 합 풀이

    문제 링크: https://www.acmicpc.net/problem/1182 백준 알고리즘 기초 2/2 540에서 2번째 - 1182번 부분수열의 합을 풀어보았다. 풀이: 파이썬은 combinations를 썼다. C++ Python from itertools import combinations n,s=map(int,input().split()) inp=list(map(int,input().split())) cnt=0 for i in range(1,n+1): a=combinations(inp,i) for b in a: if sum(b)==s: cnt+=1 print(cnt) Java

    집합 풀이

    문제 링크: https://www.acmicpc.net/problem/11723 백준 알고리즘 기초 2/2 540에서 1번째 - 11723번 집합을 풀어보았다. 풀이: 명령어를 적절하게 구현하면 된다. C++ Python import sys m=int(sys.stdin.readline()) s=set() for _ in range(m): inp=list(sys.stdin.readline().split()) if len(inp)!=2: if inp[0]=="all": s=set([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]) else: s=set() else: ord,num=inp[0],int(inp[1]) if ord=="add": s.add(num) el..

    맞춰봐 풀이

    문제 링크: https://www.acmicpc.net/problem/1248 백준 알고리즘 기초 2/2 530에서 7번째 - 1248번 맞춰봐를 풀어보았다. 풀이: https://gksdudrb922.tistory.com/238 C++ Python n = int(input()) data = input() k = 0 s = [[0] * n for _ in range(n)] for i in range(n): for j in range(i, n): if data[k] == '0': s[i][j] = 0 elif data[k] == '-': s[i][j] = -1 else: s[i][j] = 1 k += 1 def check(index): total = 0 for i in range(index, -1, -1)..

    부등호 풀이

    문제 링크: https://www.acmicpc.net/problem/2529 백준 알고리즘 기초 2/2 530에서 6번째 - 2529번 부등호를 풀어보았다. 풀이: https://great-park.tistory.com/38 를 참고했다. C++ Python def check(a,b,c): if c=='

    링크와 스타트 풀이

    문제 링크: https://www.acmicpc.net/problem/15661 백준 알고리즘 기초 2/2 530에서 5번째 - 15661번 링크와 스타트를 풀어보았다. 풀이: 스타트와 링크에서 좀 더 나아간 문제이다. 파이썬의 경우, 구글링 해서 나온 풀이가 죄다 시간초과를 먹어서 파이썬으로 푼 사람들의 코드를 보다가 찾은 https://www.acmicpc.net/source/54531477 를 참고해서 풀었다. C++ Python from itertools import combinations def diffs(st,li): ss,sl=0,0 for i,j in combinations(st,2): ss+=arr[i][j]+arr[j][i] for i,j in combinations(li,2): sl+..

    스타트와 링크 풀이

    문제 링크: https://www.acmicpc.net/problem/14889 백준 알고리즘 기초 2/2 530에서 4번째 - 14889번 스타트와 링크를 풀어보았다. 풀이: https://pottatt0.tistory.com/m/entry/%EB%B0%B1%EC%A4%80-14889-%ED%95%B4%EC%84%A4-python-%EC%8A%A4%ED%83%80%ED%8A%B8%EC%99%80-%EB%A7%81%ED%81%AC 를 참고했다. C++ Python def dfs(l,idx): global cnt if l==n//2: a=0 b=0 for i in range(n): for j in range(n): if visit[i] and visit[j]: a+=arr[i][j] elif not vis..

    퇴사 풀이

    문제 링크: https://www.acmicpc.net/problem/14501 백준 알고리즘 기초 2/2 530에서 3번째 - 14501번 퇴사를 풀어보았다. 풀이: https://jrc-park.tistory.com/119 를 참고했다. C++ Python n=int(input()) arr=[list(map(int,input().split())) for i in range(n)] dp=[0 for i in range(n+1)] for i in range(n-1,-1,-1): if arr[i][0]+i>n: dp[i]=dp[i+1] else: dp[i]=max(dp[i+1],arr[i][1]+dp[i+arr[i][0]]) print(dp[0]) Java