D - Limestone 解説
by
i_am_noob
Easier Solution (Sketch)
Let \(dp_{0,i,j}\) and \(dp_{1,i,j}\) be the count and the desired sum of all good matrices of size \(i\times j\), respectively. For the base cases, \(dp_{0,i,j}=1\) and \(dp_{1,i,j}=0\) when \(ij=0\).
When \(ij>0\), consider a fixed configuration of the last row of the matrix. Suppose that \(k\) is the smallest integer such that \(A_{i,k}=0\), or \(j+1\) if such \(k\) doesn’t exist, and there are \(r\) more \(1\)s after \(A_{i,k}\) in that row, let them be \(A_{i,c_1},A_{i,c_2},\dots,A_{i,c_r}\). Then \(A\) is good iff the \(c_1,c_2,\dots,c_r\)-th columns are all \(1\)s and after removing the last row and \(c_1,c_2,\dots,c_r\)-th columns, the resulting matrix is good. The rest is routine work for this kind of dp, separating the sum by “old” \(1\)s and “new” \(1\)s. Notice that only enumerating \(i,j,r\) is enough, so the time complexity should be \(O(HW\min(H,W))\) or \(O(HW\log \min(H,W))\) if convolution is used to speed up the transition. Also note that \(r=0\) is a special case.
\(O(HW\min(H,W))\) implementation: https://atcoder.jp/contests/arc199/submissions/66392700
\(O(HW\log \min(H,W))\) implementation: https://atcoder.jp/contests/arc199/submissions/66392764
投稿日時:
最終更新: