N과 M(3)

김준오·2021년 8월 26일
0

알고리즘

목록 보기
42/91
post-thumbnail

문제

n과m 3

풀이1 product 모듈

import sys
input = sys.stdin.readline
from itertools import product

n,m = map(int,input().split())

for i in product(range(1,n+1),repeat = m):
  print(' '.join(map(str,i)))

풀이2 재귀

import sys
input = sys.stdin.readline

n,m = map(int,input().split())

arr = []
def perm():
  if len(arr) == m:
    print(' '.join(map(str,arr)))
    return
  
  for i in range(1,n+1):
    arr.append(i)
    perm()
    arr.pop()

perm()

공부한것

product 모듈에서 repeat로 반복횟수를 정할수 있다!
product(arr, repeat = m)
끝!

profile
jooooon

0개의 댓글

관련 채용 정보