그럴듯한 개발 블로그
반응형

https://school.programmers.co.kr/learn/courses/30/lessons/12949

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

매우 오랜만에 접하는 행렬이다. 짝이 맞지 않는 케이스는 들어오지 않으니 예외처리 할 필요 없이 구현만 하면 된다. 

#include <string>
#include <vector>

using namespace std;

int get_multi(vector<vector<int>> arr1, vector<vector<int>> arr2, int i, int j)
{
    int res = 0;
    for (int idx = 0; idx < arr1[0].size(); idx++) // 반대다 행렬의 곱이니까
        res += arr1[i][idx] * arr2[idx][j];
    return res;
}

vector<vector<int>> solution(vector<vector<int>> arr1, vector<vector<int>> arr2) {
    vector<vector<int>> answer(arr1.size(), vector<int>(arr2[0].size()));
    
    for (int i = 0; i < arr1.size(); i++)
        for (int j = 0; j < arr2[0].size(); j++)
            answer[i][j] = get_multi(arr1, arr2, i, j);
    return answer;
}

/*
0,0 0,1     0,0 0,1
1,0 1,1     1,0 1,1
2,0 2,1    

(0,0)*(0,0) + (0,1)*(1,0), (0,0)*(0,1) + (0,1)*(1,1)

1 4   3 2
3 2   3 4
4 1
    
1 * 3 + 4 * 3 , 1 * 2 + 4 * 4
3 * 3 + 2 * 3 , 3 * 2 + 2 * 4
4 * 3 + 1 * 3 , 4 * 2 + 1 * 4
*/

엄청 헷갈렸다  종이랑 펜 없이는 힘들었을 듯...

반응형
profile

그럴듯한 개발 블로그

@donghyk2

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!