题面
数组含义:dp[i][j]位于(i,j)的元素向左延长的长度
状态转移:minn= min(dp[k][j],minn) 向上遍历,加入满足最小长度的矩形
代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <vector> #include <map> #include <cmath> #include <queue> using namespace std; int mapp[1005][1005]; int n,m; /*数组含义:dp[i][j]位于(i,j)的元素向左延长的长度 状态转移:min= Math.min(dp[k][j],min) 向上遍历,加入满足最小长度的矩形*/ int numSubmat(int mat[][1005]) { int res=0; int dp[1005][1005]; for(int i=0;i<n;i++) for(int j=1;j<=m;j++) dp[i][j]=mat[i][j-1]==1?dp[i][j-1]+1:0; for(int i=0;i<n;i++) for(int j=1;j<=m;j++) { int minn=1<<20; for (int k=i;k>=0;k--) if(dp[k][j]==0) break; else { minn= min(dp[k][j],minn); res+=minn; } } return res; } int main(){ cin >> n >> m; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin >> mapp[i][j]; } } int ans=numSubmat(mapp)%100007; cout << ans; return 0; }
标签:include,minn,min,int,矩阵,1005,动态,规划,dp From: https://www.cnblogs.com/anaxiansen/p/17029030.html