ベクトルと行列の積

これ

onlinejudge.u-aizu.ac.jp

問題


B=\begin{pmatrix}
b_1\\
b_2\\
b_3\\
b_4\\
\vdots\\
b_m
\end{pmatrix}
の長さmの1次元配列と

A=\begin{pmatrix}
A_{11} & A_{12} & \cdots &A_{1m}\\
A_{21} & A_{22} & \cdots &A_{2m}\\
A_{31} & A_{32} & \cdots &A_{3m}\\
\vdots & \vdots & \vdots  & \vdots\\
A_{n1} & A_{n2} & \cdots &A_{nm}\\
\end{pmatrix}
みたいなn*mの2次元配列が渡される。

これの積Cを作ってね、という問題である。

解くわよ~~~

Σの意味わからん記法は読めないからとりあえず飛ばしていこう。

とりあえずサンプルを見てみるか…


B=\begin{pmatrix}
1\\
2\\
3\\
0\\
\end{pmatrix}

A=\begin{pmatrix}
1 & 2 & 0 & 1 \\
0 & 3 & 0 & 1\\
4 & 1 & 1 & 0\\
\end{pmatrix}
の積が

C=\begin{pmatrix}
5\\
6\\
9\\
\end{pmatrix}
と…

解説

まあサンプルで考えます(楽なので)


B=\begin{pmatrix}
1\\
2\\
3\\
0\\
\end{pmatrix}
を横に倒して

B=\begin{pmatrix}
1&2&3&0
\end{pmatrix}
にするわよ(配列が横のイメージがあるので横にしました)

B

A答えって並べてみると…


\begin{pmatrix}
1&2&3&0
\end{pmatrix}\\
\begin{pmatrix}
1 & 2 & 0 & 1 \\
0 & 3 & 0 & 1\\
4 & 1 & 1 & 0\\
\end{pmatrix}
\begin{pmatrix}
5\\
6\\
9\\
\end{pmatrix}
何か気づくことはないでしょうか?

各要素の掛け算の和になってるように、感じませんか?

例えばサンプルのAの1行目だけ取り出してみて、考えてみましょう。



\begin{pmatrix}
1&2&3&0
\end{pmatrix}\\
\begin{pmatrix}
1 & 2 & 0 & 1
\end{pmatrix}
\begin{pmatrix}
5\\
\end{pmatrix}
あれ?A*Bじゃね?みたいな?わかりやすいようにA*Bを追加してみます


\begin{pmatrix}
1&2&3&0
\end{pmatrix}\\
\begin{pmatrix}
1 & 2 & 0 & 1
\end{pmatrix}\\
\begin{pmatrix}
1 & 4 & 0 & 0
\end{pmatrix}
\begin{pmatrix}
5\\
\end{pmatrix}
はい、他のも同様ですね、この問題の解き方は、Aの各列(縦)の要素とBの要素を掛け合わせたやつsの和です。