Reapportionment
Time limit7sMemory limit1024 MB
Given block populations in a rectangular town, decide whether the blocks can be split into W contiguous wards with equal total population.
- Level
Medium6 of 10
- Topics
- Backtracking, Brute force, Graph
- Solved
- No attempts yet
Problem
Here is an example of a small town made of blocks with a population of 99. The colors highlight one way to divide the town into 3 contiguous wards of 33 citizens each. Your task is to consider towns of various sizes and determine whether the blocks can be divided into contiguous wards of equal population. All towns are rectangular and have no more than 25 blocks. The number of desired wards may vary. Two blocks are adjacent if they share an edge. A contiguous ward is a set of blocks such that, starting from any one block and moving only to adjacent blocks in the ward, you can reach every block in the ward.
Input
The first line contains two integers and (), the number of rows and columns of the rectangular town. The next line contains an integer (), the number of wards desired. The next lines each contain non-negative integers, the populations of the blocks in each row, starting from the top row. Blocks in each row are listed from left to right. The total population of the town is no more than .
Output
If the reapportionment is possible with the given input, print "Yes". Otherwise, print "No".