You have taken the graduation picture of graduates. The picture could be regarded as a matrix A of n×nn \times nn×n, each element in A is 0 or 1, representing a blank background or a student, respectively.
However, teachers are too busy to take photos with students and only took a group photo themselves. The photo could be regarded as a matrix B of 1×m1 \times m1×m where each element is 2 representing a teacher.
As a master of photoshop, your job is to put photo B into photo A with the following constraints:
you are not allowed to split, rotate or scale the picture, but only translation.
each element in matrix B should overlap with an element in A completely, and each teacher should overlap with a blank background, not shelter from a student.
Please calculate the possible ways that you can put photo B into photo A.
输入描述:
1 2 3 4 5
The firstlinecontainstwo integers n,m(1≤n,m≤2000) indicating the size of photos A and B.
In the next $n$ lines,eachlinecontains n charactersof'0'or'1',representing the matrix A.
The lastlinecontains m charactersof'2', representing matrix B.
constint INF = 1e9; constint N = 2e3 + 10; int n, m; LL ans; char a[N][N]; voidsolve(){ int i, j; char c; cin >> n >> m; fore (i, 1, n) { cin >> a[i]; }
fore (i, 1, n) { int k = 0; fore (j, 0, n - 1) { if (a[i][j] == '1') { k = 0; } else { k++; } if (k >= m) { ans++; } } }