A potentially cheaper option is to use capacitive sensing.
Each block would have a capacitor connected across its two terminals. When you plug multiple blocks together the capacitance for each would add up. There are application notes for measuring capacitance using an ADC, so you could work out the total capacitance and divide it by the known capacitance of a single block.
You wouldn't have to then have switches to separate each block when you connect them.