C - Another Brick in the Wall

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

After years as a brick-layer, you've been called upon to analyze the instability of brick walls. The instability of a wall can be approximated by the maximum damage to a wall in case of taking one brick out. A brick will fall if all bricks that are directly underneath it are removed. Note that if the space underneath a brick is partially empty, it does not fall. You are given the description of all bricks in a wall, and must determine the instability of the wall as described in the following sections.

Input

There are multiple test cases in the input. Each test case consists of a single line, ``M N " (1M, N100) where M and N indicate the height and width (in units), respectively, of the input wall.

Each of the next M lines is a string of N digits which specifies a row in the wall. Each brick in a row is represented by a substring of the row (like s
) such that every digit in s is the same, which is equal to the length of s
too. For example, 333 and 22 are two bricks of length 3 and 2
respectively, but 111 specifies three bricks of length one. A 0 in a row
means there is no brick in that place of wall. Note that the height of
each brick is one. The input terminates with a line containing `
0 0'. You may assume that the input is correct. This means:

  1. There is no brick such that the length of the brick does not conform to the digits in the brick (like 222 in the row 12221).
  2. No brick can fall initially.

Output

For each test case, write a single line containing maximum sum of the
bricks' lengths that will fall if we take one brick out (including that
brick).

Sample Input

4 5
33322
22333
33322
22333
4 6
122333
444422
111111
333333
3 3
022
220
111
0 0

Sample Output

5
8
4
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100001
const int inf=0x7fffffff; //无限大
int dp[][];
int g[][];
int q[][];
int main()
{
int n,m;
string s[];
while(cin>>n>>m)
{
if(n==&&m==)
break;
memset(dp,,sizeof(dp));
memset(q,,sizeof(q));
memset(g,,sizeof(g));
for(int i=;i<n;i++)
{
cin>>s[i];
for(int j=;j<m;j++)
{
if(s[i][j]=='')
{
g[i][j]=-;
}
else
{
g[i][j]=(int)(s[i][j]-'');
j=j+(int)(s[i][j]-'')-;
}
}
} for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(i==)
{
dp[i][j]=(int)(s[i][j]-'');
}
else
{
if(g[i][j]==-)
dp[i][j]=;
else if(g[i][j]==)
dp[i][j]=dp[i][j-];
else
{
int ii=i-;
int sum=;
int op=g[i][j];
dp[i][j]+=g[i][j]; for(int k=;k<m;k++)
{
if(j<=k&&k<j+op)
q[i][k]=-;
else
q[i][k]=g[i][k];
} while()
{
sum=; for(int k=;k<m;k++)
{
if(q[ii][k]==-)
continue;
q[ii][k]=g[ii][k];
for(int jj=;jj<g[ii][k];jj++)
{
if(q[ii+][k+jj]!=-)
break;
if(jj==g[ii][k]-)
{
for(int mm=;mm<g[ii][k];mm++)
{
q[ii][k+mm]=-;
sum++;
}
}
}
}
dp[i][j]+=sum;
if(sum==)
break;
ii--;
if(ii<)
break;
}
memset(q,,sizeof(q));
}
}
}
}
int ans=;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
ans=max(ans,dp[i][j]);
}
}
cout<<ans<<endl;
}
return ;
}
												

UVALive 4425 Another Brick in the Wall 暴力的更多相关文章

  1. UVALive 7077 - Little Zu Chongzhi's Triangles(暴力)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  2. UVaLive 6623 Battle for Silver (最大值,暴力)

    题意:给定一个图,让你找一个最大的子图,在这个子图中任何两点都有边相连,并且边不交叉,求这样子图中权值最大的是多少. 析:首先要知道的是,要想不交叉,那么最大的子图就是四个点,否则一定交叉,然后就暴力 ...

  3. ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall (暴力)

    题意:一个n*m的方格矩阵,有的格子被涂成了黑色,问该矩阵中有多少个子矩阵,子矩阵不包含黑色格子; 思路:对于一个长为L, 高为H的无黑点矩阵中包含的高为H的子矩阵个数为L+(L-1)+(L-2)+. ...

  4. 2015 UESTC Winter Training #4【Regionals 2008 :: Asia - Tehran】

    2015 UESTC Winter Training #4 Regionals 2008 :: Asia - Tehran 比赛开始时电脑死活也连不上WIFI,导致花了近1个小时才解决_(:зゝ∠)_ ...

  5. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  6. 489. Robot Room Cleaner扫地机器人

    [抄题]: Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or block ...

  7. Kafka Streams开发入门(5)

    1. 背景 上一篇演示了split操作算子的用法.今天展示一下split的逆操作:merge.Merge算子的作用是把多股实时消息流合并到一个单一的流中. 2. 功能演示说明 假设我们有多个Kafka ...

  8. 554. Brick Wall最少的穿墙个数

    [抄题]: There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. ...

  9. UVALive 7070 The E-pang Palace 暴力

    The E-pang Palace Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/problem ...

随机推荐

  1. 理解mipi协议【转】

    转自:http://blog.csdn.net/wanglining1987/article/details/50202615 完成mipi信号通道分配后,需要生成与物理层对接的时序.同步信号: MI ...

  2. MVC Ajax Form & Ajax Valida(笔记)

    1.引入必要的文件 <script src=.min.js")" type="text/javascript"></script> &l ...

  3. openjudge-NOI 2.5基本算法之搜索 专题题解目录

    1.1700 八皇后问题 2.1756 八皇后 3.1789 算24

  4. Nginx实现代理和用户验证

    1.下载Nginx 首先去官网http://nginx.org/en/download.html下载需要的版本即可,无需安装,只需要打开nginx.exe文件,nginx.exe的服务就开启了.打开h ...

  5. git clone命令使用

    git clone命令使用 分类: 项目构建2013-06-26 15:43 38660人阅读 评论(2) 收藏 举报 GitClone git clone 命令参数: usage: git clon ...

  6. luoguP2735 电网 Electric Fences

    一道校内模拟赛遇见的题 ** 不会正解就真的很麻烦的 数学题 ** 有一种东西叫 皮克定理 发现的千古神犇: 姓名:George Alexander Pick(所以叫皮克定理呀 国籍:奥地利(蛤!竟然 ...

  7. 洛谷P2300 合并神犇

    传送门啦 分析: 刚开始读完题后感觉很懵,怎么算都不是3,结果发现题目理解错了.题目要求的是求一个不降的序列,不是递减的(发现自己好傻) 看明白题就好做了吧.经典的区间dp题,合并果子大家应该都做过, ...

  8. NYOJ 石子合并(一)(区间DP)

    题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=737 题目大意: 有N堆石子排成一排,每堆石子有一定的数量.现要将N堆石子并成为一堆 ...

  9. python图片处理(二)

    python中图像处理有pillow和skimage 图像中一般有个RGBA值,RGB顾名思义就是红绿蓝值,A表示alpha表示是透明度. from PIL import ImageColor pri ...

  10. JAVA复习笔记之多线程并发

    前言:多线程并发编程是Java编程中重要的一块内容,也是面试重点覆盖区域,还是值得深入研究一下 概念: 1 线程:进程中负责程序执行的执行单元线程本身依靠程序进行运行线程是程序中的顺序控制流,只能使用 ...