codeforces 22B B. Bargaining Table(dp)
2015-10-04 16:27
507 查看
题目链接:
codeforces 22B题目大意:
给出一个矩阵,求周长最大的矩形的周长题目分析:
求出每个点为底的最大的高度(0),然后枚举右下角,再枚举矩形的高度,然后算取长度,进而算取周长即可。AC代码:
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #define MAX 30 using namespace std; int n,m; char a[MAX][MAX]; int h[MAX][MAX]; int l[MAX][MAX]; int r[MAX][MAX]; int main ( ) { while ( ~scanf ( "%d%d" , &n , &m ) ) { for ( int i = 0 ; i < n ; i++ ) scanf ( "%s" , a[i] ); for ( int i = 0 ; i < n ; i++ ) for ( int j = 0 ; j < m ; j++ ) { if ( a[i][j] == '1' ) { h[i][j] = 0; continue; } if ( i == 0 || a[i-1][j] == '1' ) h[i][j] = 1; else h[i][j] = h[i-1][j] + 1; } int ans = 0; for ( int i = 0 ; i < n ; i++ ) for ( int j = 0 ; j < m ; j++ ) for ( int k = 1 ; k <= h[i][j] ; k++ ) { int l = j; while ( l >= 0 && h[i][l] >= k ) l--; ans = max ( ans , (j-l)+k ); } printf ( "%d\n" , ans*2 ); } }
相关文章推荐
- 基于Android中dp和px之间进行转换的实现代码
- Android中dip、dp、sp、pt和px的区别详解
- LFC1.0.0 版本发布
- Android px、dp、sp之间相互转换
- android中像素单位dp、px、pt、sp的比较
- Android对px和dip进行尺寸转换的方法
- Android根据分辨率进行单位转换-(dp,sp转像素px)
- android 尺寸 dp,sp,px,dip,pt详解
- DP问题各种模型的状态转移方程
- POJ-1695-Magazine Delivery-dp
- nyoj-1216-整理图书-dp
- TYVJ1193 括号序列解题报告
- 对DP的一点感想
- TYVJ上一些DP的解题报告
- soj1005. Roll Playing Games
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces 407C Codeforces Round #239 (Div. 1)C
- 01背包问题