hdu1505 dp:01矩形中最大面积全0矩阵
被输入坑了233333
另外感觉我这方法好像不太对的样子。。but找不到数据算了ac了==
1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 int up[1005][1005],down[1005][1005],l1[1005][1005],r1[1005][1005],l2[1005][1005],r2[1005][1005]; 6 char s[1005][1005],ss[1005]; 7 int main() 8 { 9 int T,n,m,i,j,maxx,x; 10 scanf("%d",&T); 11 while (T--) 12 { 13 scanf("%d%d",&m,&n); 14 getchar(); 15 for (i=1;i<=m;i++) 16 for (j=1;j<=n;j++){ 17 scanf("%s",&ss); 18 s[i][j]=ss[0]; 19 } 20 maxx=0; 21 memset(up,0,sizeof(up)); 22 memset(down,0,sizeof(down)); 23 for (i=1;i<=m;i++) 24 for (j=1;j<=n;j++) 25 if (s[i][j]=='F') up[i][j]=up[i-1][j]+1; 26 for (i=m;i>=1;i--) 27 for (j=1;j<=n;j++) 28 if (s[i][j]=='F') down[i][j]=down[i+1][j]+1; 29 30 for (i=1;i<=m;i++) 31 { 32 l1[i][1]=1; r1[i][n]=n; 33 for (j=2;j<=n;j++) 34 { 35 x=j; 36 while (x>1&&up[i][x-1]>=up[i][j]) x=l1[i][x-1]; 37 l1[i][j]=x; 38 } 39 for (j=n-1;j>=1;j--) 40 { 41 x=j; 42 while (x<n&&up[i][x+1]>=up[i][j]) x=r1[i][x+1]; 43 r1[i][j]=x; 44 } 45 46 l2[i][1]=1; r2[i][n]=n; 47 for (j=2;j<=n;j++) 48 { 49 x=j; 50 while (x>1&&down[i][x-1]>=down[i][j]) x=l2[i][x-1]; 51 l2[i][j]=x; 52 } 53 for (j=n-1;j>=1;j--) 54 { 55 x=j; 56 while (x<n&&down[i][x+1]>=down[i][j]) x=r2[i][x+1]; 57 r2[i][j]=x; 58 } 59 for (j=1;j<=n;j++) 60 { 61 x=(up[i][j]+down[i][j]-1)*(min(r1[i][j],r2[i][j])-max(l1[i][j],l2[i][j])+1); 62 if (x>maxx) maxx=x; 63 } 64 } 65 printf("%d\n",maxx*3); 66 } 67 }