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 ...
随机推荐
- 使用netcat的正向 / 反向shell
reverse shell bind shell reverse shell描述图: 在此示例中,目标使用端口4444反向连接攻击主机.-e选项将Bash shell发回攻击主机.请注意,我们也可以在 ...
- Flask: Quickstart解读
Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2 从示例代码说起: from flask import Flask app = Flask(__name__) @app ...
- 金融数据分析 - 利用 Tushare Pro 平台 获取金融数据
Tushare金融大数据开放社区 免费提供各类金融数据和区块链数据 , 助力智能投资与创新型投资. 详见 https://tushare.pro/
- /touch滑屏事件
//touch滑屏事件 var windowHeight = $(window).height(), $body = $("body"); $body.cs ...
- vue+vuex+axios+echarts画一个动态更新的中国地图
一. 生成项目及安装插件 # 安装vue-cli npm install vue-cli -g # 初始化项目 vue init webpack china-map # 切到目录下 cd china- ...
- matlab随笔(二)
circshift 两种形式 :第一种Y = circshift(A,K)就不用说了,将A中的元素向右移动K个位置. 需要注意的是第二种形式:Y = circshift(A,K,dim),这种形式不好 ...
- » Working Around JNI UTF-8 Strings Deprogramming
private static native void printString(String text); ... void examplePrintString() { String str = &q ...
- nsis安装包_示例脚本语法解析
以下是代码及解析,其中有底色的部分为脚本内容. 注释.!define.变量.!include.常量 ; Script generated by the HM NIS Edit Script Wizar ...
- 【Java】 Scanner类的几个方法
通过 Scanner 类可以获取用户的输入,创建 Scanner 对象的基本语法如下: Scanner sc = new Scanner(System.in); nextInt().next()和ne ...
- Linq To Sql 使用初探
最近有数据处理需要,就是那种从数据库中把数据取出来 ,对其中的部分字段做一些处理再吐回去的工作,从同事那里学习到了,这中活最适合使用 Linq to Sql 这种方式,不用搭建框架,不用自建实体,直接 ...