codeforce:1720C
# codeforces 1720C
# The problem
C. Corners
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given a matrix consisting of n rows and m columns. Each cell of this matrix contains 0 or 1.
Let’s call a square of size 2×2 without one corner cell an L-shape figure. In one operation you can take one L-shape figure, with at least one cell containing 1 and replace all numbers in it with zeroes.
Find the maximum number of operations that you can do with the given matrix.Input
The first line contains one integer t (1≤t≤500) — the number of test cases. Then follow the descriptions of each test case.
The first line of each test case contains two integers n and m (2≤n,m≤500) — the size of the matrix.
Each of the following n lines contains a binary string of length m — the description of the matrix.
It is guaranteed that the sum of n and the sum of m over all test cases does not exceed 1000.
Output
For each test case output the maximum number of operations you can do with the given matrix.
# At first, I didn’t have a clue. So I tried to do a brute force. Didn’t work out of course.The data volume is too large. So I was wondering whether it could be solved by dynamic programing. I tried this:
sum[x][y]=max(sum[x-1][y-1]+b[x][y]-b[x-1][y-1],sum[x-2][y-2]+b[x][y]-b[x-2][y-2])