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下内存泄漏工具

    概述 内存泄漏(memory leak)指由于疏忽或错误造成程序未能释放已经不再使用的内存的情况,在大型的.复杂的应用程序中,内存泄漏是常见的问题.当以前分配的一片内存不再需要使用或无法访问时,但是却 ...

  2. js中this揭秘

    前端面试题中经常会考this指向问题,初学者通常都会晕头转向,不知所以然.今天我就来讲讲js中this指向问题. this指向大概分为5种情况,记住这6个规律,基本上面试题都能解决. 通过圆括号直接调 ...

  3. ExtJs的Reader

    ExtJs的Reader Reader : 主要用于将proxy数据代理读取的数据按照不同的规则进行解析,讲解析好的数据保存到Modle中 结构图 Ext.data.reader.Reader 读取器 ...

  4. Linux学习笔记:mkdir创建文件夹

    文件夹,即目录,在linux中使用mkdir创建. 语法:mkdir dir_name 通过 mkdir 命令可以实现在指定位置创建以 dir_name(指定的文件名)命名的文件夹或目录.要创建文件夹 ...

  5. Ansible之tags介绍

    本节内容: tags介绍 一.tags介绍 我们每次改完配置文件,比如上一篇博客中的的apache.yml,没必要把整个playbook都运行一遍,只需要运行改变了的task.我们可以给task一个标 ...

  6. Ansible常见模块介绍

    本节内容: ansible命令基础 常见模块举例 一.ansible命令基础 语法: ansible <host-pattern> [-f forks] [-m module_name] ...

  7. 一行代码实现Okhttp,Retrofit,Glide下载上传进度监听

    https://mp.weixin.qq.com/s/bopDUFMB7EiK-MhLc3KDXQ essyan 鸿洋 2017-06-29 本文作者 本文由jessyan投稿. jessyan的博客 ...

  8. Android Studio3.x新的依赖方式(implementation、api、compileOnly)

    https://blog.csdn.net/yuzhiqiang_1993/article/details/78366985?locationNum=6&fps=1 Android Studi ...

  9. Iterator 迭代器

    意图 提供一种方法顺序访问一个聚合对象中各个元素 , 而又不需暴露该对象的内部表示. 动机 一个聚合对象, 如列表(list), 应该提供一种方法来让别人可以访问它的元素,而又不需暴露它的内部结构 迭 ...

  10. 【51nod】1149 Pi的递推式

    题解 我们把这个函数的递归形式画成一张图,会发现答案是到每个出度为0的点的路径的方案数 这个可以用组合数算 记录一下P[i]为i减几次PI减到4以内 如果P[i + 1] > P[i],那么转向 ...