UVALive 4425 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, N
100) 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:
- 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).
- 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 暴力的更多相关文章
- UVALive 7077 - Little Zu Chongzhi's Triangles(暴力)
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- UVaLive 6623 Battle for Silver (最大值,暴力)
题意:给定一个图,让你找一个最大的子图,在这个子图中任何两点都有边相连,并且边不交叉,求这样子图中权值最大的是多少. 析:首先要知道的是,要想不交叉,那么最大的子图就是四个点,否则一定交叉,然后就暴力 ...
- ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall (暴力)
题意:一个n*m的方格矩阵,有的格子被涂成了黑色,问该矩阵中有多少个子矩阵,子矩阵不包含黑色格子; 思路:对于一个长为L, 高为H的无黑点矩阵中包含的高为H的子矩阵个数为L+(L-1)+(L-2)+. ...
- 2015 UESTC Winter Training #4【Regionals 2008 :: Asia - Tehran】
2015 UESTC Winter Training #4 Regionals 2008 :: Asia - Tehran 比赛开始时电脑死活也连不上WIFI,导致花了近1个小时才解决_(:зゝ∠)_ ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- 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 ...
- Kafka Streams开发入门(5)
1. 背景 上一篇演示了split操作算子的用法.今天展示一下split的逆操作:merge.Merge算子的作用是把多股实时消息流合并到一个单一的流中. 2. 功能演示说明 假设我们有多个Kafka ...
- 554. Brick Wall最少的穿墙个数
[抄题]: There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. ...
- 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 ...
随机推荐
- 查看gcc的默认宏定义命令【转】
转自:http://blog.csdn.net/cywosp/article/details/10730931 有些时候我们在编写代码或者阅读开源项目时经常会遇到一些陌生的宏定义,在找遍所有源代码都没 ...
- linq和ef关于group by取最大值的两种写法
LINQ: var temp = from p in db.jj_Credentials group p by p.ProfessionID into g select new { g.Key, Ma ...
- docker stack 部署 mysql 5.6
=============================================== 2018/7/1_第1次修改 ccb_warlock === ...
- scala可变长度参数(转)
可变长度参数 Scala 允许你指明函数的最后一个参数可以是重复的.这可以允许客户向函数传入可变长度参数列表.想要标注一个重复参数,在参数的类型之后放一个星号.例如: scala> def ec ...
- MYSQL-重做系统恢复MYSQL过程
记笔记是好习惯,记笔记是好习惯,记笔记是好习惯! 重要的事情说三遍. 说多了都是泪.第一次装MYSQL时候就遇到了很多问题,当时解决了忘记记录了.家里硬盘满了,于是买了个4T的硬盘重装系统.重装系统后 ...
- 使用JS实现文字搬运工
使用JS实现文字搬运工 效果图: 代码如下,复制即可使用: <!DOCTYPE html> <html><head><meta http-equiv=&quo ...
- kickstart配置LINUX无人值守选项--rootpw
linux kickstart rootpw密码可以使用明文,也可以使用加密过的值(密码为:IPPBXADMINROOT) 注意:在这里要使用加密过的值,否则安全性就太低了 rootpw --iscr ...
- c 语言文本文件判断是否到达结尾的问题
在c语言中,判断文件结尾有两种方法,第一种是使用feof()函数,feof(fp)用于测试fp所指向的文件的当前状态是否为“文件结束”.如果是,函数则返回的是非0值(真),否则为0(假),要注意的是, ...
- CCF CSP 201503-4 网络延时
CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201503-4 网络延时 问题描述 给定一个公司的网络,由n台交换机和m台终端电脑组成,交换机 ...
- day6 xml文件格式的处理
XML处理模块 xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单,不过,古时候,在json还没诞生的黑暗年代,大家只能选择用xml呀,至今很多传统公 ...