문제링크 - https://www.acmicpc.net/problem/17406
17406번: 배열 돌리기 4
크기가 N×M 크기인 배열 A가 있을때, 배열 A의 값은 각 행에 있는 모든 수의 합 중 최솟값을 의미한다. 배열 A가 아래와 같은 경우 1행의 합은 6, 2행의 합은 4, 3행의 합은 15이다. 따라서, 배열 A의
www.acmicpc.net
[풀이]
- 일반적인 순열 조합 문제와 배열 돌리기가 합쳐진 문제였다.
- 회전 정보로 중복없는 순열을 perm 함수를 구현하고, 회전 정보에 맞춰서 배열을 돌리는 rotate 함수를 구현해주었고, 어렵지 않게 풀 수 있었다.
from copy import deepcopy
def rotation(n_maps,i):
r,c,s=rots[i][0]-1,rots[i][1]-1,rots[i][2]
dx,dy=(0,1,0,-1),(1,0,-1,0)
for d in range(s,0,-1):
x,y,dir,tmp=r-d,c-d,0,n_maps[r-d][c-d]
while dir<4:
nx,ny=x+dx[dir],y+dy[dir]
if r-d<=nx<=r+d and c-d<=ny<=c+d:
n_maps[nx][ny],tmp=tmp,n_maps[nx][ny]
x,y=nx,ny
else:
dir+=1
def perm(z,maps, check):
if z==k:
global result
for row in maps:
result=min(result,sum(row))
else:
for i in range(k):
n_maps = deepcopy(maps)
if check[i]: continue
check[i]=True
rotation(n_maps,i)
perm(z+1,n_maps,check)
check[i]=False
n,m,k=map(int, input().split())
arr=[list(map(int, input().split())) for _ in range(n)]
rots=[list(map(int, input().split())) for _ in range(k)]
check=[False for _ in range(k)]
result=float('inf')
perm(0,arr,check)
print(result)
'Algorithm > 백준' 카테고리의 다른 글
[백준-9184] 신나는 함수 실행 (Python) (0) | 2021.02.23 |
---|---|
[백준-1003] 피보나치 함수 (Python) (0) | 2021.02.23 |
[백준-2580] 스도쿠 (Python) (0) | 2021.02.23 |
[백준-1400] 화물차 (Python) (0) | 2021.02.01 |
[백준-17836] 공주님을 구해라! (Python) (0) | 2021.02.01 |
댓글