problem-2740

ysysc·2022년 11월 17일
0

PS

목록 보기
24/47

과정
temp1 에 b행렬의 열들을 행으로 변환시켜 저장
곱하기

분할 정복으로 풀 수도 있지만, 이렇게 푸는것도 문제 없다.

a,b=[],[]
n,m=map(int,input().split())
for _ in range(n):
    a.append(list(map(int,input().split())))
m,k=map(int,input().split())
for _ in range(m):
    b.append(list(map(int,input().split())))

temp1=[]
for i in range(k):
    t=[]
    for j in range(m):
        t.append(b[j][i])
    temp1.append(t)

temp2=[]
for i in range(n):
    temp3=[]
    for temp in temp1:
        result=0
        for t in range(len(temp)):
            result+=a[i][t]*temp[t]
        temp3.append(result)
    temp2.append(temp3)
ans=temp2
        
for i in ans:
    for j in i:
        print(j,end=' ')
    print('')

time:60분

행렬 곱 구현에 오래걸렸다.

0개의 댓글