HDU-4328-Cut the cake
来源:互联网 发布:mac如何截取网页全屏 编辑:程序博客网 时间:2024/05/18 04:00
昨天比赛没做出来这个题,今天看了某人的博客,转至去看了悬线,然后做了下。地址:http://blog.sina.com.cn/s/blog_8d5787ed010193oz.html
其实把矩阵进行转换的时候还是比较巧妙的,比如0,1混合的时候就把加起来为奇数的块变换下值就行了
代码:
#include<cstdio>#include<cstring>#include<iostream>using namespace std;const int maxn=1100;int n,m,ans,a[maxn][maxn],b[maxn][maxn],L[maxn][maxn],R[maxn][maxn],H[maxn][maxn];char str[maxn];void solve(){ for(int i=0;i<n;i++) { int sl=-1,sr=m; for(int j=0;j<m;j++) { if(a[i][j]) sl=j; L[i][j]=sl; } for(int j=m-1;j>=0;j--) { if(a[i][j]) sr=j; R[i][j]=sr; } } for(int j=0;j<m;j++) { H[0][j]=1; if(R[0][j]-L[0][j]-1+H[0][j]>ans) ans=R[0][j]-L[0][j]-1+H[0][j]; } for(int i=1;i<n;i++) { for(int j=0;j<m;j++) { if(a[i-1][j]) H[i][j]=1; else { H[i][j]=H[i-1][j]+1; L[i][j]=max(L[i-1][j],L[i][j]); R[i][j]=min(R[i-1][j],R[i][j]); } if(R[i][j]-L[i][j]-1+H[i][j]>ans) ans=H[i][j]+R[i][j]-L[i][j]-1; } }}int main(){ int T,cas=1; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); for(int i=0;i<n;i++) { scanf("%s",str); for(int j=0;j<m;j++) { if(str[j]=='B') b[i][j]=1; else b[i][j]=0; } } ans=0; //处理0矩阵 for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=b[i][j]; solve(); //处理1矩阵 for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=1-b[i][j]; solve(); //处理0,1混合 for(int i=0;i<n;i++) for(int j=0;j<m;j++) { if((i+j)&1) a[i][j]=1-b[i][j]; else a[i][j]=b[i][j]; } solve(); //处理0,1混合 for(int i=0;i<n;i++) for(int j=0;j<m;j++) { if((i+j)&1) a[i][j]=b[i][j]; else a[i][j]=1-b[i][j]; } solve(); printf("Case #%d: %d\n",cas++,ans*2); } return 0;}
0 0
- HDU 4328 - Cut the cake
- hdu 4328 Cut the cake
- hdu 4328 Cut the cake
- hdu 4328 Cut the cake
- HDU-4328-Cut the cake
- HDU 4328 Cut the cake
- hdu - 4328 - Cut the cake - dp
- [HDU 4328] Cut the cake (悬链法)
- HDU 4762 Cut the Cake
- HDU-4762 Cut the Cake
- hdu 4328 cut the cake#单调队列#DP
- HDU 4328 Cut the Cake(动态规划)
- hdu 4328 Cut the cake 最大子矩阵
- HDU 4328 Cut the cake 最大相同子矩阵, 悬线法
- HDU 4328 Cut the cake(最大子矩阵+悬线法)
- hdu 4762 - Cut the Cake(大数)
- hdu 4762 Cut the Cake(高精度&概率)
- hdu 4762 Cut the Cake(高精度)
- git基础
- 利用Java反射机制-访问Android隐藏API
- 解决固网 HU-1608n 更换主板后不能打印的问题
- maven (一):目录结构
- RTSP H264 提取bmp图片
- HDU-4328-Cut the cake
- View和viewController的生命周期
- poj 1068: Parencodings
- 安卓蓝牙通信
- 从轻量级产品设计到重量级产品经理的转化
- Count Color 线段树
- Ubuntu 14.04 LTS 删除最近使用文件 Ubuntu Recent File & Folder
- OOM killer分析
- paparazzi 堆栈