For example,
The first (0-index) column of B is the sum of the columns 1, 2 and 5 of A because V has 0 in these positions.
The second (1-index) column of B is zero because the V vector has no value 1.
The third (2-index) column of B is the sum of the columns 0, 3 and 4 of A because V has 2 in these positions.
The fourth (3-index) column of B is zero because the V vector has no value 3.