[HDU 1505 City Game] HDU1506加强版

hdu1505 City Game二维01矩阵求最大矩形周长 City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2837    Accepted Submission(s): 1142 Problem Description Bob is a strategy ga 阅读详情

题目链接  http://acm.hdu.edu.cn/showproblem.php?pid=1505

City Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5711    Accepted Submission(s): 2464


Problem Description
Bob is a strategy game programming specialist. In his new city building game the gaming environment is as follows: a city is built up by areas, in which there are streets, trees,factories and buildings. There is still some space in the area that is unoccupied. The strategic task of his game is to win as much rent money from these free spaces. To win rent money you must erect buildings, that can only be rectangular, as long and wide as you can. Bob is trying to find a way to build the biggest possible building in each area. But he comes across some problems – he is not allowed to destroy already existing buildings, trees, factories and streets in the area he is building in.

Each area has its width and length. The area is divided into a grid of equal square units.The rent paid for each unit on which you're building stands is 3$.

Your task is to help Bob solve this problem. The whole city is divided into K areas. Each one of the areas is rectangular and has a different grid size with its own length M and width N.The existing occupied units are marked with the symbol R. The unoccupied units are marked with the symbol F.
 

Input
The first line of the input contains an integer K – determining the number of datasets. Next lines contain the area descriptions. One description is defined in the following way: The first line contains two integers-area length M<=1000 and width N<=1000, separated by a blank space. The next M lines contain N symbols that mark the reserved or free grid units,separated by a blank space. The symbols used are:

R – reserved unit

F – free unit

In the end of each area description there is a separating line.
 

Output
For each data set in the input print on a separate line, on the standard output, the integer that represents the profit obtained by erecting the largest building in the area encoded by the data set.
 

Sample Input
  
2 5 6 R F F F F F F F F F F F R R R F F F F F F F F F F F F F F F 5 5 R R R R R R R R R R R R R R R R R R R R R R R R R
 

Sample Output
  
45 0
 

Source
 

简单的dp吧。。稍微想一下就行了,处理一下它给的图,例如第一个样例可以处理成

011111
122222
000333
111444
222555
开一个数组dp[i][j],每一行遍历一次,若是F,就加上上一行的dp值,求出连续F的个数,若遇到R就归0

如下:

for (int i = 1; i <= n; i++)
{
	for (int j = 1; j <= m; j++)
	{
		if (map[i][j] == 'R')
		dp[i][j] = 0;
		else dp[i][j] = dp[i - 1][j] + 1;
	}
}
得出每一行的数列后,就可以发现这题和HDU1506一毛一样,只是1506求一行,这题要求多行并取最大值

HDU 1506 题解 http://blog.youkuaiyun.com/chenninggo/article/details/48080271

注意下输入,因为卡输入wa了几次,也算是学到了特殊的输入技巧

代码如下。。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int t;
int n, m;
char map[1010][1010], ch[5];
int dp[1010][1010], l[1010], r[1010];
int main()
{
//  freopen("input.txt", "r", stdin);
	scanf("%d", &t);
	while (t--)
	{
		scanf("%d%d", &n, &m);
		for (int i = 1; i <= n; i++)            //这种输入法真的好好用。。
			for (int j = 1; j <= m; j++)
			{
				scanf("%s", ch);
				map[i][j] = ch[0];
			}
		memset(dp, 0, sizeof(dp));
		for (int i = 1; i <= n; i++)         //处理一下原图
		{
			for (int j = 1; j <= m; j++)
			{
				if (map[i][j] == 'R')
					dp[i][j] = 0;
				else dp[i][j] = dp[i - 1][j] + 1;
			}
		}
		int ans = -1, mx, id;
		for (int i = 1; i <= n; i++)
		{
			memset(l, 0, sizeof(l));
			memset(r, 0, sizeof(r));
			l[1] = 1;
			r[m] = m;
			for (int j = 2; j <= m; j++)             //和1506一样的方法
			{
				id = j;
				while (id > 1 && dp[i][j] <= dp[i][id - 1])
					id = l[id - 1];
				l[j] = id;
			}
			for (int j = m - 1; j >= 1; j--)
			{
				id = j;
				while (id < m && dp[i][j] <= dp[i][id + 1])
					id = r[id + 1];
				r[j] = id;
			}
			mx = -1;
			for (int j = 1; j <= m; j++)
				mx = max(mx, (r[j] - l[j] + 1)*dp[i][j]);
			ans = max(mx, ans);
		}
		printf("%d\n", ans * 3);
	}
	return 0;
}






scRNA-seq | 吐血整理的单细胞入门教程(从原理到代码实操)(二) 阅读详情

相关推荐

CAN-do-paser:Java开发的CAN总线数据帧解析库

CAN总线数据帧使用DBC文件信息解析为物理量,基于Java开发的数据解析工具。

佳瑞的博客 1133

poj_A Chess Game2425

A Chess Game Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3094   Accepted: 1266 Description Let's design a new chess game. There are N positions to hold M

u012631715的专栏 576

KF-gins输出结果绘图

KF-gins输出结果绘图

m0_51977577的博客 1107

HDU1505 City Game (DP,HDU1506加强版)

链接: http://acm.hdu.edu.cn/showproblem.php?pid=1505 没做过1506的建议先去做1506,我有详细解释 1506链接:http://blog.youkuaiyun.com/xtttgo/article/details/48085707 因为我是用1506的方法做的这题 题意:R是障碍物,求最大的F形成的矩形 实际上,我们把R的情况去掉,就是跟150

xtttgo的博客 387

Drools vs URule:5个真实项目场景告诉你如何选择开源规则引擎

本文通过电商风控、物流计费、会员体系、保险定价和物联网告警五个真实项目场景,深度对比了Drools与URule两款开源规则引擎。分析了两者在规则复杂度、性能表现、开发运维及适用场景上的核心差异,为技术选型提供基于实战的决策指南。

k6l7m8n9的博客 944

深入解析FPGA中的GTX高速收发器架构与设计原理

本文深入解析了FPGA中GTX高速收发器的核心架构与设计原理。文章将GTX比作数据“高速公路”,详细拆解了其PMA(物理媒介适配层)与PCS(物理编码子层)的双层结构,阐述了串并转换、时钟恢复等关键技术,并提供了时钟源选型(QPLL/CPLL)、上电复位流程及信号完整性调试等实战指南,是掌握高速接口设计的必备知识。

f6g7h8i9j的博客 219

hdu1505—City Game(1506的加强版)

题目链接:传送门 City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7143    Accepted Submission(s): 3097 Problem Description

zhiyuanjiang的博客 302

1.triton镜像使用

1)拉取镜像2)启动容器指定模型仓库时可以执行server下的./fetch_model.sh,见2.2部分GPU版本的启动CPU版本的启动区别只在于--gpus=1这个参数注意:docker19.03之前的版本使用gpu要指定显卡硬件名,docker19.03之后的需要安装nvidia-container-toolkit或nvidia-container-runtime安装之后要重启docker查看gpus参数是否安装成功重新执行我遇到了如下错误先使用非GPU版本的。

天启的博客 2077

hdu 1505 city game(1506加强版)dp

题目大意:        给你一个n*m的矩阵,里面包含F或者是R,现在问你,用F组成一个矩阵,最大面积是多少。       题目和1506很相似,都是一个求最大矩阵面积的问题。只不过1505稍微复杂了一下,用了一个二维的,并且需要对字符串进行处理。 题目分析:       首先对字符串进行处理分析,然后再对每行进行如1506的操作,最后求得最大值就行了,详见代码解析。#include #

Tsaryu的博客 464

城市规划师必备:ArcMap里用这个免费工具,5步完成建筑群通风廊道分析

本文介绍了城市规划中利用ArcMap进行建筑群通风廊道分析的高效方法,重点讲解了迎风面投影指数(FAI)的应用。通过5个步骤,从数据准备到规划应用,帮助规划师快速评估城市通风潜力,优化建筑布局,提升城市风环境质量。

weixin_26800111的博客 412

Macbook Pro上如何修改brew源

一、需求说明 我的macbook电脑安装了中科大的brew源码,发现安装gpg工具失败,其他工具可以正常安装,为了能将gpg安装成功,就找了找切换brew源的方案,记录如下。 二、切换至国内源 由于使用github默认源有可能存在路径远或者部分服务访问超时的原因,切换至国内源可以提速。 2.1 替换brew.git $ cd "$(brew --repo)" # 中国科大: $ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git #

bufegar0的博客 1079

hdu 1505 City Game (hdu1506加强版)

# include # include # include # include using namespace std; char a[1010][1010]; int dd[1010][1010];///宽度 int r[1010],l[1010]; int main() { int t,i,j,n,m,max1; while(~scanf("%d",&t)) {

苍竹林 682

新能源汽车电机交流电流测量系统精度全链路分析

通过全链路误差建模与瓶颈分析,结合硬件选型优化与软件算法补偿,可将系统精度从4.2%提升至≤1% FS。本文所述方法论已应用于某800V电驱平台开发,实测电流控制精度达±0.8%,为高性能电机控制奠定基础。为例,深入剖析从互感器采集到CAN报文解析的全链路信号处理流程,揭示各环节误差来源及对最终精度的影响,为研发测试提供理论支撑。:±0.1%(电阻温漂与运放开环增益限制):运放增益带宽积(GBW)不足导致高频衰减。:±0.02%/℃(铁氧体材料温敏特性):±0.5%读数(磁芯饱和效应)

优快云-新能源汽车研发测试专业博主 1493

hdu 1505 city game (1506 加强版)

#include<iostream> #include<cstdio> #include<cstring> using namespace std; char ss[33]; int b[1002][1002],qian[1002],hou[1002]; int main() { int i,j,n,m,t; sc...

weixin_30347335的博客 107

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

HDU 1505 City Game (hdu1506 dp二维加强版)

F - City Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1505 Appoint description: Description Bob is a strategy game pr...

weixin_30486037的博客 130

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

HDU1505--City Game(动态规划)(1506加强版)

这道题和1506差不多,多加了一维,只要求出每个F点上面的F点个数,然后压到一行中,就和1506一样了。 #include #include #include #include #include #define maxn 1005 using namespace std; struct Map { char c[5]; int num; int left,right; }map

慕枫幕影的专栏 886

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

HDU-1505-City Game——算法笔记

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1505 Problem Description: Bob is a strategy game programming specialist. In his new city building game the gaming environment is as follows: a city is b...

学而不思则忘 441

HDU-1505-City Game【dp】【思维】

HDU-1505-City Game

Linoy 1186

【DP】 hdu1505 City Game

City Game http://acm.hdu.edu.cn/showproblem.php?pid=1505 Problem Description Bob is a strategy game programming specialist. In his new city building game the gaming environment is as foll

Ted's 游乐园 2679

HDU 1505 City Game(DP求二维最大子矩阵)

City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5913    Accepted Submission(s): 2533 Problem Description Bob is a strategy ga

HHH的专栏 445

HDU 1505 City Game

自己学的太死了。 也用不上刚学的。 这个题就是 对于一行lai

Shimmer_的专栏 780

hdu1505 City Game(DP)

思路:HDU1506的加强版,只要把算出以i 行为底能达到的最到的最大高度,再扫描每一行,就转化为 HDU1506 的问题了 #include using namespace std; const int maxn = 1005; int a[maxn][maxn]; int l[maxn],r[maxn]; int main() { int T; scanf("%d",&T);

围巾的ACM博客 284

City Game HDU - 1505(单调栈)

City Game HDU - 1505题意:开发商在一块m*n的地皮上建楼房, 一直这块地有空地和已用地, 空地用F表示, 已用地用R表示, 每单位面积的地皮市值3$, 求出这整块地皮上价值最大的一块矩形地皮;HDU 1506 ...

Sirius_han的博客 276

HDU 1505 动态规划(DP) City Game

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1505 分析; [HDU 1506的深化版]每输入一行,更新一次高度,就变成了1505题的问题了.[本题深化版HDU 2870] #include #include #include #include #include #include using namespace std; int

PWZER 876

hdu1506 1505 2870最大子矩形 DP

Largest Rectangle in a Histogram

hccz95的专栏 1049
上一篇: [HDU 1506 Largest Rectangle in a Histogram] ...类dp?...
下一篇: [HDU 2602 Bone Collector] 宇宙无敌入门01背包
chenningGo
博客等级 码龄11年 1粉丝 17原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值