Part5.13_완전탐색_부분집합 구하기(DFS)_라이브러리를 이용한 순열(수열 추측하기3)_Combinations

Eugenius1st·2022년 1월 27일
0

Python_algorithm

목록 보기
41/83

내가 생각한 코드의 문제

조합 구성에서 중복을 어떻게 배제할까...?

import sys
sys.stdin = open("input.txt", "rt")
import itertools as it
n, f= map(int,input().split())
a = list(map(int,input().split()))
m = int(input())
cnt = 0
for i in it.permutations(a, f):
    sum = 0
    print(i)
    for x in i:
        sum += x
    if sum % 6 == 0:
        cnt+=1
print(cnt)

어!!! 조합은 permutations 가 아니라 combinations를 쓰면 되는구나 ㅋㅋㅋㅋㅋ
라이브러리 이름 자체가 다름...

선생님 코드

import sys
sys.stdin = open("input.txt", "rt")
import itertools as it
n, k= map(int,input().split())
a = list(map(int,input().split()))
m = int(input())
cnt = 0
for i in it.combinations(a, k):
    if sum(i)%m ==0:
        cnt+=1
print(cnt)

하지만 있다는 것만 알고 너무의존하지 말라..

profile
최강 프론트엔드 개발자가 되고싶은 안유진 입니다

0개의 댓글