Write a number in every cell. Equal numbers that are neighbours either horizontally or vertically automatically belong to the same group. Every group needs to consist of exactly as many cells as this number indicates. This means you can not have two groups with the same number sharing a border. More information.