NEED HELP USING DP......

Revision en1, by fakeac, 2016-11-10 19:43:35
You have been given a n*n matrix consisting of 0's and 1's.You need to find the number of squares in the matrix such that it contains no 1's (All entries should be 0).

Constraints:
1=<n<=5000

Input:
First line consists of a single integer n.
Each of the next n lines consist of a binary string of length n.
Output:
Output just one integer, the answer as described above.

Sample:
Input:
3
000
000
000
Output:
14
Explanation: There are 9=> 1 * 1 squares, 4=> 2 * 2 squares and 1=> 3 * 3 square.

Input:
2
10
10
Output:
2
Explanation: There are 2=> 1 * 1 squares. All other squares contain a 1.

Input:
2
11
11
Output:
0

Input:
1
0
Output:
1
Tags #dp, hashing, #data structure

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English fakeac 2016-11-10 19:43:35 1282 Initial revision (published)