Tensor networks and counting problems on the lattice