HDU 2870 最大子矩阵,联系1505, 1506
2012-02-23 22:03
363 查看
题目意思:w x y z 可以转化,求最大子矩阵。
思路:枚举后转换为 hdu 1505 hdu 1506 的情况。
可以转化为a的有:w,y, z
可以转化为b的有:w,x, z
可以转换为c的有:x, y, z
所以
a, w, y, z一组
b, w, x, z一组
c, x, y, z一组
分别dp
思路:枚举后转换为 hdu 1505 hdu 1506 的情况。
可以转化为a的有:w,y, z
可以转化为b的有:w,x, z
可以转换为c的有:x, y, z
所以
a, w, y, z一组
b, w, x, z一组
c, x, y, z一组
分别dp
#include <cstdlib> #include <iostream> using namespace std; const int maxn=1005; int h[maxn][maxn]; int l[maxn],r[maxn]; char str[maxn][maxn]; int n,m,i,j; int ans; int max(int a,int b) { if(a>b) return a; else return b; } void DP() { for(i=1;i<=n;++i) { for(j=1;j<=m;++j) l[j]=r[j]=j; h[i][0]=h[i][m+1]=-1; for(j=1;j<=m;++j) while(h[i][j]<=h[i][l[j]-1]) l[j]=l[l[j]-1]; for(j=m;j>=1;j--) while(h[i][j]<=h[i][r[j]+1]) r[j]=r[r[j]+1]; for(j=1;j<=m;++j) ans=max(ans,h[i][j]*(r[j]-l[j]+1)); } } int main() { memset(h[0],0,sizeof(h[0])); while(scanf("%d%d",&n,&m)!=EOF) { ans=0; for(i=1;i<=n;++i) scanf("%s",str[i]+1); for(i=1;i<=n;++i) for(j=1;j<=m;++j) if(str[i][j]=='a'||str[i][j]=='w'||str[i][j]=='y'||str[i][j]=='z') h[i][j]=h[i-1][j]+1; else h[i][j]=0; DP(); for(i=1;i<=n;++i) for(j=1;j<=m;++j) if(str[i][j]=='b'||str[i][j]=='w'||str[i][j]=='x'||str[i][j]=='z') h[i][j]=h[i-1][j]+1; else h[i][j]=0; DP(); for(i=1;i<=n;++i) for(j=1;j<=m;++j) if(str[i][j]=='c'||str[i][j]=='x'||str[i][j]=='y'||str[i][j]=='z') h[i][j]=h[i-1][j]+1; else h[i][j]=0; DP(); printf("%d\n",ans); } return 0; }
相关文章推荐
- 动态规划求最大子矩阵详解(hdu 1505,1506 , 2870)
- 0和1中的最大子矩阵(1506加强版)(1505和2870)
- HDU 1505 1506 2830 2870求最大矩阵面积 DP
- hdu 1505 /hdu 1506(最大子矩阵)
- hdu 2870 最大子矩阵 单调队列优化+dp
- HDU 2870 Largest Submatrix (最大子矩阵)
- HDU 2870(动态规划-最大子矩阵)
- hdu 1506(dp求最大子矩阵)
- hdu 1506 Largest Rectangle in a Histogram ((dp求最大子矩阵))
- hdu 1505 单调栈(最大子矩阵)
- HDU 2870 Largest Submatrix (找最大子矩阵)
- hdu 1505(dp求最大子矩阵)
- hdu 1506 Largest Rectangle in a Histogram ((dp求最大子矩阵))
- hdu 1505 && hdu1506 &&hdu 2830 && 2870 总结---------DP之状图选最大矩形
- hdu 2870(dp求最大子矩阵)
- hdu 1505 1506 2870 dp小礼包
- HDU 1506 1505 2870 2830
- HDU-1506 || HDU-1505 || HDU-2870 || HDU-2830
- hdu---1506(Largest Rectangle in a Histogram/dp最大子矩阵)
- HDU 1506 Largest Rectangle in a Histogram(dp求最大子矩阵和)