[Question]
  [
## Introduction
There is a small village with nothing but a few houses and empty fields.
The local bureaucrats want to divide the village into lots so that each lot contains exactly one house, and the borders of the lots form a nice straight-line grid.
Your task is to determine whether this is possible.
## The task
Your input is a rectangular 2D array of bits; 1 represents a house and 0 an empty field.
Its size will be at least **1×1**, and it will contain at least one 1.
You can take the input in any reasonable format (nested list of integers, list of strings, multiline string etc).
Your program shall determine whether the array can be divided into grid cells using straight horizontal and vertical lines so that each grid cell contains exactly one 1.
The grid cells may have different sizes and shapes, although they will always be rectangular.
The lines must run from one edge of the array to the opposite edge.
For example, the following is a valid division of an array:
```
00|0010|01|1
01|0000|00|0
--+----+--+-
00|0000|00|1
01|0010|01|0
--+----+--+-
01|1000|10|1
```
whereas the following division is not valid, since there are grid cells with no 1s or more than one 1:
```
00|0010|01|1
--+----+--+-
01|0000|00|0
00|0000|00|1
01|0010|01|0
--+----+--+-
00|1000|10|1
```
If a valid division exists, you shall output a truthy value, and otherwise a falsy value.
## Rules and scoring
You can write a full program or a function.
The lowest byte count wins.
## Test cases
```
[[1]] -> True
[[0,1],[1,0]] -> True
[[1,1],[1,0]] -> False
[[1,0,1],[0,1,0]] -> True
[[1,0],[0,1],[0,1]] -> True
[[1,0,0],[0,0,1],[0,1,1]] -> True
[[1,1,1],[1,1,1],[1,1,1]] -> True
[[1,0,1],[0,1,0],[1,0,0]] -> True
[[1,0,0],[1,0,0],[0,1,1]] -> False
[[0,0,0,0,1],[1,0,0,1,0],[0,0,0,1,0]] -> False
[[0,0,1,0,1],[0,0,0,1,0],[0,0,0,0,0]] -> True
[[1,1,0,0,0],[0,0,0,0,0],[1,0,1,0,0]] -> True
[[1,1,0,1,1],[0,1,0,1,1],[1,0,0,0,0]] -> True
[[0,0,0,0,0,0,0],[0,1,1,1,0,1,0],[0,1,0,0,1,0,0],[0,0,0,0,0,0,1],[0,0,1,0,0,0,1],[1,1,0,1,1,0,0]] -> False
[[1,1,0,0,0,0,0],[1,0,1,1,0,1,0],[0,0,0,0,1,0,0],[0,1,0,1,1,0,0],[1,0,0,0,1,1,0],[0,0,0,0,0,1,0]] -> False
[[0,1,0,1,1,1,0],[0,0,0,0,1,0,0],[0,0,0,0,0,0,0],[1,0,0,1,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,1]] -> True
[[0,1,0,0,1,0,1],[1,0,0,0,1,0,1],[0,0,1,0,1,0,1],[1,0,0,0,1,1,0],[0,0,0,1,1,1,0],[0,1,0,0,1,0,1]] -> True
[[0,1,0,0,1,0,0,1,0],[0,0,0,0,1,1,0,1,0],[1,1,0,0,1,0,0,0,0],[0,0,1,0,1,0,1,0,0],[0,0,1,0,1,0,1,0,0],[0,1,0,0,0,1,0,0,1],[0,1,0,0,0,0,1,0,0]] -> False
[[1,0,1,0,0,1,1,0,1],[0,1,1,0,0,1,1,0,1],[1,0,0,0,0,1,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,1,0,0,0,0,1,1],[0,1,1,0,1,0,1,0,1],[1,0,1,0,0,1,1,0,1]] -> True
```
  
[Answer]
# Pyth, ~~30~~ ~~29~~ ~~26~~ ~~24~~ 23 bytes
```
sm.Asmmq1ssbCkds./MC./M
```
[Try it online.](https://pyth.herokuapp.com/?code=sm.Asmmq1ssCbCkds.%2FMC.%2FM&input=%5B%5B1%2C0%2C0%5D%2C%5B0%2C0%2C1%5D%2C%5B0%2C1%2C1%5D%5D&debug=0)
I'm sure this will get shorter. This is **O(2*mn*)**, where *m* and *n* are the width and height of the array, but completes the last two test cases in 45 seconds on my laptop on battery (i5-5200U with limited performance).
Outputs the number of solutions.
### Explanation
Five-dimensional arrays are really fun to work with.</sarcasm> You are not supposed to understand how this works even with the explanation.
```
                    ./M    Find all partitions of each row. Now we have a list of rows,
                           each containing the ways to split the row, each containing
                           the parts of the split (3D).
                   C       Transpose. Now we have a list of ways to split the columns,
                           each containing the rows, each containing the parts of the
                           row (3D).
                ./M        Find all partitions of each row list. Now we have a list of
                           ways to split the columns, each containing the ways to split
                           the rows, each containing the bunch of rows, each containing 
                           the rows in the bunch, each containing the parts of the row
                           (6D).
               s           Combine the ways to split rows & columns into one array (5D).
 m            d            Do the following for each way to split rows & columns (4D):
     m       k                 Do the following for each bunch of rows (3D):
            C                      Transpose the array. We now have a list of column
                                   groups, each containing the row parts (3D).
      m    b                       Do the following for each column group (2D):
          s                            Combine the row parts in the column group. We now
                                       have the list of cells in this row/column group
                                       (1D).
         s                             Sum the cells.
       q1                              Check if the sum is one.
                                   We now have the list of booleans that tell if each
                                   row/column group is valid (1D).
                               We now have the 2D list of booleans that tell if each
                               row/column group in each bunch of rows is valid. (2D)
    s                          Combine the 2D list of booleans to 1D.
  .A                           Check if all values are truthy; if the split is valid.
                           We now have the validity of each split.
s                          Sum the list to get the number of valid solutions.
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 22 bytes
```
ŒṖḅ1S€€=1Ȧ€
SŒṖ⁸ṁþÇ€FS
```
[Try it online!](https://tio.run/nexus/jelly#dVExDsMgDJybtzBwD@jaPoAR8ZhUqrp36BM69QHJ0iWq1G8kH6EkGGwClRDG9vl8Nv5zn8fHPFxhlssrnCO@z2A6syWWfpjHfnpPtxA7Gb/Zs/e2O1gL59RqtYJTFkqTj8qPiHDLWIzQzcgY5wrOJV5pyzqu59zKlfgQX7mHVEQe9d3jtJyOfJmL3Khw4Mmz7pIvc0jthNe5NnGrAp@0opiRerU0F1pRzSj3xxysGfudFPtLNf84daVBt3bZnFP24H@C6CF3UefLP0djt6FH534 "Jelly – TIO Nexus")
[Answer]
# [Haskell](https://www.haskell.org/), 116 bytes
```
import Data.List
m(a:b)=[a:e|e<-m b]++[zipWith(+)a d:e|d:e<-m b];m e=[e]
d=(any$any$all$all(==1)).map(m.transpose).m
```
[Try it online!](https://tio.run/nexus/haskell#dVM9b8QgDN3zKxg6JDoa4fVaOnXs3gExcEqkIh25KGFp1f@eki@wSToQwDbv@dnOZF3/GDx7N97UH3b0hSvN9VZJZa7tb/v67NhNXy7qx/af1n@Vl8qwJnjCWn0vjrVStbpoZGm676dl3e/zKqWEqqqd6UtX@8F0Y/8Y22CYnLGd7Afb@TmONUop0JorJTiEDbhYbmEPJx6sqz18OWwe2CLxviLMUXv8dotnEZFhu2HPwrx6UBREbhHZMFb0ZEyQ4yMOccZ/cgfEkHQBYth1wqkfZ4QzxHh7pSG9SdXObMCJumP@uGMoFuPlmVIOrdlbwVgYo3UsTgcilRa3XZAkqXRBogR@vyeUFebYCiprH7tYJjpYZKDgMIZYQUL4r3VUAx6gHDUxAYmjbYFM49EGpM1AbPEX0cX0Bw "Haskell – TIO Nexus")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 20 bytes
```
ŒṖS€€ỊȦ$ÐfZ€µ⁺€Ȧ€€FS
```
This is still a brute-force solution, but it's quite a bit faster than my other answer – which cannot cope with the last two test cases on TIO – and handles all test cases in ~4 seconds.
[Try it online!](https://tio.run/nexus/jelly#dVO7DcIwEK3JHJQufEvAAOmI3LIHNEhUiIIRUtFSAB0RUtYgixhH/tw725GSOPd79@7Ztt/r73lrp@PdPb/3eezXw2W/c8bnMR1ebh17H9y0dji5dWtt16y6joxR86oVGdWR0sGmwvYZ7os@7wlfzvR@ruBYxMVV1nE9x2asiEf@L/VARsEKffM8jdMFG2Mem4o84skTb4mXMJB7yNepNmIrkR@5kpgx9KpxFlypmBH1YwzmTLkmQr9Ys4SpCw66pmV1TuzB@0TQA7Uo43LPqaJtrUepD2tGIg/OLbzLPmQOt0NoBrcHu6czIn1ZdalpxidNBHi5drKHacwf "Jelly – TIO Nexus")
### How it works
```
ŒṖS€€ỊȦ$ÐfZ€µ⁺€Ȧ€€FS  Main link. Argument: M (matrix, array of rows)
ŒṖ                    Compute all partitions, i.e., all groupings of M's rows.
  S€€                 Map sum over all individual groupings, collapsing the grouped
                      rows into a single row.
        Ðf            Filter; keep only those partially collapsed matrices for
                      which the link to the left returns a truthy value.
       $                Group the two links to the left into a monadic chain.
     Ị                    Insignificant; map 0 and 1 to 1, greater integers to 0.
      Ȧ                   All; return 1 iff the matrix contains no zeroes.
          Z€          Zip/transpose all kept matrices,
            µ         Combine all links to the left into a monadic chain.
             ⁺€       Duplicate the chain and map it over the individual results
                      from the first call. We now have all possible combinations
                      of row and column groupings (represented by the corresponding
                      matrices of collapsed rows and columns) that do not have a
                      2 anywhere. However, they still may contain zeroes.
               Ȧ€€    Map the all atom over the matrices, returning 1 only for
                      matrices that consist entirely of ones.
                  FS  Flatten and sum, counting the number of valid divisions.
```
]