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. linux下C获取系统时间的方法

    asctime(将时间和日期以字符串格式表示)  相关函数 time,ctime,gmtime,localtime  表头文件 #include  定义函数 char * asctime(const ...

  2. CCScale9Sprite 的 setContentSize setPreferredSize 区别

    CCScale9Sprite 设置图片大小方式: updateButtonSpriteMark->setContentSize(size);//设置图片的原始大小设置节点的未转换大小.无论节点被 ...

  3. 虚拟机 windows xp sp3 原版

    原版的镜像:http://www.7xdown.com/Download.asp?ID=3319&URL=http://d5.7xdown.com/soft2/&file=Window ...

  4. LCT解读(1)

    蒟蒻的LCT解读(1) 前段时间本蒟蒻自学了一下LCT,但是网上的很多资料并不很全,而且作为一个数组选手,我看指针代码真的很麻烦,所以就在这里写一篇数组选手能看懂的代码. LCT的初步了解 LCT全称 ...

  5. Javascript之对象的创建

    面向对象语言有一个非常显著的标志,那就是它们都有类的概念,通过类之间的继承就可以达到任意创建具有相同属性方法的对象.而在ECMAScript中并没有类的概念,它把对象定义为:无序属性的集合,其属性包含 ...

  6. CxGrid 表格标题头居中

    选中这些列后 搞.

  7. POJ 2516 Minimum Cost(拆点+KM完备匹配)

    题目链接:http://poj.org/problem?id=2516 题目大意: 第一行是N,M,K 接下来N行:第i行有K个数字表示第i个卖场对K种商品的需求情况 接下来M行:第j行有K个数字表示 ...

  8. MySQL学习笔记:新增一列

    1.在一个已建好的表中,最后一列位置添加一列,可使用: ALTER TABLE aa_numbers_small ADD COLUMN date_time DATE NOT NULL; 2.添加一列到 ...

  9. Python 安装 pytesser 处理验证码出现的问题

    今天这个问题困扰了我好久,开始直接用 pip install pytesseract 安装了 pytesseract 然后出现了如下错误 Traceback (most recent call las ...

  10. Hex Dump In Many Programming Languages

    Hex Dump In Many Programming Languages See also: ArraySumInManyProgrammingLanguages, CounterInManyPr ...