2019牛客第八场A All-one Matrices(单调栈)
鏈接:https://ac.nowcoder.com/acm/contest/888/A
題目描述
Gromah and LZR entered the great tomb, the first thing they see is a matrix of size n×mn\times mn×m, and the elements in the matrix are all 00_{}0? or 11_{}1?.
LZR finds a note board saying “An all-one matrix is defined as the matrix whose elements are all 11_{}1?, you should determine the number of all-one submatrices of the given matrix that are not completely included by any other all-one submatrices”.
Meanwhile, Gromah also finds a password lock, obviously the password should be the number mentioned in the note board!
Please help them determine the password and enter the next level.
輸入描述:
The first line contains two positive integers n,mn,m_{}n,m?, denoting the size of given matrix.
Following nn_{}n? lines each contains a string with length mm_{}m?, whose elements are all 00_{}0? or 11_{}1?, denoting the given matrix.
1≤n,m≤30001\le n,m \le 30001≤n,m≤3000
輸出描述:
Print a non-negative integer, denoting the answer.
輸入
3 4
0111
1110
0101
輸出
5
說明
The 5 matrices are (1,2)?(1,4),??(1,2)?(2,3),??(1,2)?(3,2),??(2,1)?(2,3),??(3,4)?(3,4)(1,2)-(1,4), ; (1,2)-(2,3), ; (1,2)-(3,2), ; (2,1)-(2,3), ; (3,4)-(3,4)_{}(1,2)?(1,4),(1,2)?(2,3),(1,2)?(3,2),(2,1)?(2,3),(3,4)?(3,4)?.
賽后補題,賽場上一點思路沒有。。
poj上有一個最大全一矩陣的題目,也是單調棧的題目。但是沒想起來怎么用單調棧解決這個問題。對于每一個num[i][j]我們記錄它向上的連續一的個數,然后枚舉每一行,從前向后枚舉列。單調找維護兩個東西,就是向上的最長長度和矩陣的最左位置pos。那么我們把最上最左可到達的距離記錄下來了,不能向右擴,那么只看能不能向下擴就行了。如果不能的話,就到頭了。
代碼如下:
努力加油a啊,(o)/~
總結
以上是生活随笔為你收集整理的2019牛客第八场A All-one Matrices(单调栈)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Codechef REBXOR HYSB
- 下一篇: Gemstones(牛客第八场多校)