import java.util.*;
public class SparseMatrix {
private static int N = 10;
public static void main(String[] args) {
SparseVector[] matrix = new SparseVector[N];
for(int i = 0; i < N; i++) {
matrix[i] = new SparseVector();
matrix[i].addValue(i, 1);
}
SparseVector b = new SparseVector();
b.addValue(0, 1);
b.addValue(N - 1, 1);
double[] c = new double[N];
for(int i = 0; i < N; i++) {
c[i] = matrix[i].dot(b);
}
System.out.print("[");
for(int i = 0; i < N - 1; i++) {
System.out.print(c[i] + ",");
}
System.out.println(c[N-1] + "]");
}
}
class SparseVector {
private Map<Integer, Double> sv = new HashMap<>();
public void addValue(int key, double value) {
sv.put(key, value);
}
public double dot(SparseVector that) {
double sum = 0;
for(Integer key: this.sv.keySet()) {
if(that.sv.get(key) != null) {
sum += this.sv.get(key) * that.sv.get(key);
}
}
return sum;
}
}