티스토리 뷰
728x90
반응형
Baekjoon Online Judge
Baekjoon Online Judge 프로그래밍 문제를 풀고 온라인으로 채점받을 수 있는 곳입니다.
www.acmicpc.net
<나의 풀이>
from itertools import combinations
n, s = map(int, input().split())
nums = list(map(int, input().split()))
result = 0
for i in range(1, n+1):
combin = list(combinations(nums, i))
for j in combin:
if sum(j) == s:
result += 1
print(result)
<다른 사람의 풀이>
# lys74423님 코드
import sys
input=sys.stdin.readline
from collections import deque
def dfs(x,Sum):
global cnt
if(x>n-1):
return
Sum+=arr[x]
if(Sum==s):
cnt+=1
dfs(x+1,Sum)
dfs(x+1,Sum-arr[x])
n,s=map(int,input().split())
arr=list(map(int,input().split()))
cnt=0
dfs(0,0)
print(cnt)
# <배운점>
# => dfs를 이용한 점
# park345601님 코드
import sys
from itertools import combinations
IN = sys.stdin.readline().split()
while IN[0] != '0':
cm = combinations(IN[1:], 6)
for c in cm:
print(' '.join(c))
print()
IN = sys.stdin.readline().split()
# <배운점>
# => 코드를 간략하게 짠 점
# 더 간략히
# pse1202님 코드
# n,s=map(int,input().split());x=[0]
# for i in map(int,input().split()):x+=[i+b for b in x]
# print(x.count(s)-(s==0))
728x90
반응형
'[그 외] > ㄴ (코테연습 : 파이썬 ver)' 카테고리의 다른 글
[백준] 14225번 : 부분수열의 합 (파이썬) (0) | 2021.07.06 |
---|---|
[백준] 6603번 : 로또 (파이썬) (0) | 2021.07.06 |
[프로그래머스] 땅따먹기 (파이썬) (0) | 2021.07.04 |
[프로그래머스] 다음 큰 숫자 (파이썬) (0) | 2021.06.30 |
[프로그래머스] 숫자의 표현 (파이썬) (0) | 2021.06.29 |
댓글
250x250
반응형
TAG
- 조합
- 알고리즘
- 월간 코드 챌린지 시즌2
- 이진탐색
- 문법
- level2
- 정렬
- 프로그래밍언어
- 프로그래머스문제
- 백준
- 알고리즘문제
- 코드잇
- 컴퓨터개론
- 설치
- 프로그래머스 프로그래머스문제
- KAKAO
- 파이썬
- level1
- 유닉스커맨드
- Summer/Winter Coding(~2018)
- 피보나치
- 파이썬문법
- 프로그래머스
- SWiFT
- 프로그래머스코딩테스트
- x만큼간격이있는n개의숫자
- 코딩테스트
- 월간 코드 챌린지 시즌1
- 재귀함수
- GIT
최근에 달린 댓글
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
링크
- Total
- Today
- Yesterday