【DP】 hdu1505 City Game

『杭电1505』City Game 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 th 阅读详情

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 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

就是 hdu1506的加强版,在每行求l,r数组就可以了。

hdu1506题解见http://blog.youkuaiyun.com/acm_ted/article/details/7847018

#include<cstdio>
#include<cstring>
using namespace std;
#define max(a,b) ((a)>(b)?(a):(b))
int l[1005],r[1005];
int h[1005];
int main()
{
    int cas,n,m,ans;
    char s[5],c;
    scanf("%d",&cas);
    for(; cas--;)
    {
        ans=0;
        memset(h,0,sizeof(h));
        scanf("%d%d",&n,&m);
        h[0]=h[m+1]=-1;
        for(int i=1; i<=n; ++i)
        {
            for(int j=1; j<=m; ++j)
            {
                scanf("%s",s);//这里的输入比较纠结,要注意输入可能会有多余的回车或者空格
                if(s[0]=='F') h[j]++;
                else          h[j]=0;
            }
            for(int j=1;j<=m;++j) l[j]=r[j]=j;
            for(int j=1;j<=m;++j)
                for(;h[l[j]-1]>=h[j];l[j]=l[l[j]-1]);
            for(int j=m;j>=1;--j)
                for(;h[r[j]+1]>=h[j];r[j]=r[r[j]+1]);
            for(int j=1;j<=m;++j)
                ans=max(ans,h[j]*(r[j]-l[j]+1));
        }
        printf("%d\n",ans*3);
    }
    return 0;
}

来源: http://blog.youkuaiyun.com/ACM_Ted

城市群快速生成插件GSG_CityKit_1.2 城市群快速生成插件GSG_CityKit_1.2 内附安装教程 立即下载

相关推荐

万达电影 com.wandafilm.app headers check

万达电影 安卓逆向 抓包 逆向 check

weixin_43786514的博客 1438

【UVA1330】City game

题面   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 b

清疚的博客 589

别再硬啃C代码了!用Simulink的Matlab Function模块手把手教你搭建CRC8校验模型(附完整M脚本)

本文详细介绍了如何利用Simulink的Matlab Function模块轻松实现CRC8校验模型,替代传统的C代码编写。通过可视化建模和即时验证,开发者可以高效完成算法设计,并自动生成嵌入式代码。文章包含完整的M脚本示例和工程实践技巧,特别适合嵌入式系统开发人员提升工作效率。

weixin_42520661的博客 183

【UVALive】3029.City Game<C++>

#include<cstdio> #include<cstring> #include<iostream> using namespace std; char input[1001][1001],judge; int up[1001][1001],Left[1001][1001],Right[1001][1001]; int main(){ int m,n,lnear,rnear,answe

天某的小窝 628

Figma到Axure一键转换:Axhub Extension保姆级教程(含常见问题解决)

本文提供Axhub Extension的保姆级教程,详细讲解如何将Figma设计稿一键转换为Axure高保真交互原型。教程涵盖环境准备、核心转换四步走流程,并重点解决JSON导入失败、样式错乱、复杂组件转换等常见问题,旨在打通Figma与Axure之间的数据孤岛,大幅提升设计师和产品经理的原型制作效率。

night的博客 1576

WSL2 + Open3D点云可视化踩坑全记录:从GLFW报错到VcXsrv配置,一篇讲清所有‘坑’

本文详细解析了在WSL2环境中使用Open3D进行点云可视化时遇到的常见问题,特别是GLFW报错和VcXsrv配置问题。通过系统性的解决方案和高级配置技巧,帮助开发者彻底解决图形显示、驱动加载和库版本冲突等难题,实现高效的点云可视化。

weixin_30627341的博客 101

单调队列 最大矩形面积

最大矩阵 解题思路第1种算法: 这道题使用了单调栈的思想,不过用单调队列也不是不可以。 首先来介绍一下什么是单调栈。 单调栈与单调队列相似,都是保持容器里面保持一种单调性,区别就在于栈和队列这两个容器的本质性能的不同。 回到题目,这道题要求求出最大的矩形的面积。 进行计算的时候,每一个宽度为1,高度为h的矩形的右边一定要比它本身高不然无法计数出以他本身为起点的矩形的面积,因此我们只需要维护一个单调递增的栈,如果我们遇到了右边比左边大的情况,我们只能计算它本身。 加个图理解一下: .

zhao_list的博客 448

ABAP RAP 行为建模深入学习:从 Behavior Definition 到 Behavior Implementation 的完整实践指南

ABAP RAP开发指南:业务行为定义与实现 本文介绍SAP RAP框架中业务对象行为的开发方法: 分层设计 Behavior Definition声明业务能力(增删改查、校验、动作等) Behavior Implementation在ABAP类中编写具体逻辑 核心组件 使用BDL定义业务行为 通过FOR BEHAVIOR OF绑定行为池类(ABP) 在本地类实现校验/确定/动作逻辑 关键特性 支持managed/unmanaged两种实现模式 提供草稿表、并发控制等企业级功能 通过EML以别名访问实体 开

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 413

最大矩形面积 (单调队列)

目录 目录 目录 最大矩形面积  题目 代码 正解 代码(2) 附(矩形牛棚) 代码(3) 最大矩形面积  题目 此题很容易想到的一个方法莫过于暴搜了, 代码 #include&lt;cstdio&gt; #define L 100000 + 5 #define LL long long #include&lt;iostream&gt; using namespa...

qq_43904786的博客 842

planning模块(6)-参考线的平滑(二次规划)

上一篇已经介绍了采样点生成锚点数据的过程,并且将所有采样点生成的锚点数据设置到了平滑器中.接下来继续介绍使用二次规划平滑参考线的算法过程.从锚点数据中提取坐标存入raw_point2d,提取横向边界存入anchorpoints_lateralbound,将起点和终点的横向边界设置为0,防止车在起点和终点位置偏离车道中心线.

让复杂的问题变得更容易理解 788

手把手教您国内安装 Claude Code 并配置自定义大模型(包含New-API中转和可视化管理工具的使用)

国内免魔法畅用 Claude Code!手把手教你 Windows 安装、配置文件写法、对接阿里百炼 / DeepSeek / 智谱✨,附完整参数、正确命令、三方工具管理方案,新手一次成功!✅

XiaoqiangClub的博客 3783

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

AUTOSAR进阶图解==>AUTOSAR_SWS_COM

AUTOSAR COM模块是AUTOSAR通信堆栈的核心组件,提供信号导向的通信服务。该模块位于通信服务层,连接RTE与PDU Router,主要功能包括信号封装/提取、传输模式管理、信号路由、超时监控和字节序转换等。COM模块架构分为应用层、通信服务层和通信抽象层,包含信号管理、I-PDU处理、传输模式管理等组件。其配置结构包括顶层容器、I-PDU组、I-PDU和信号等多层次配置对象,支持丰富的参数设置。模块采用严格的状态管理机制,包括模块状态和I-PDU组状态转换,确保通信可靠性。

一名留德华的,康德的信徒的,专注于汽车电子领域的博客 1244

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

HDU-1505-City Game

Linoy 1186

深度学习工具包 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")

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

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

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

HDU 1505 City Game(DP)

1506的升级版 只是多了一维 h要自己算 详情看上一篇

Good morning,good afternoon and good night 1063

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

HDU 1505 City Game (DP)

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): 3929    Accepted Submission

fcbruce 812

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

hdu 1505 City Game dp

题意:最大F子矩阵 * 3 每行处理出里(i,j)最左最有的不小于mat【i】【j】的数组,然后更新答案 #include #include #include #include #include #include #include #include #include #include #include ///cout << fixed << setprecision(

uuuuuu 345

hdu1505city game dp

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

MissZhou要努力 702

hdu 1505 City Game dp

给你一个矩阵,让你找最大的矩形面积,F代表3,R代表 0,。 输入用%s 输入 #include #include #include #include #define maxn 1010 using namespace std; int ma[maxn][maxn]; int h[maxn]; int fact(int m) { int a,sum=0; stackq;

HLSHYR的博客 371

HDU 1505 City Game dp

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1505题意:给定一个n*m的矩阵,矩阵里每个点只有R和F两种,要求划分出一个只含有F的矩阵,求这个矩阵的最大面积思路:跟HDU1506很像,以矩阵的每一行作为底,把这一行之上的矩阵部分压缩为一维,就可以用1506的方法求了。#include <bits/stdc++.h> using namespace st

弱智就要多努力 432

HDU - 1505 City Game(dp)

题意:求由R和F组成的矩阵中,最大的由F组成的矩阵面积。 分析: 1、hdu1506http://www.cnblogs.com/tyty-Somnuspoppy/p/7341431.html与此题相似。 2、将矩阵的每行看成1506中的坐标轴分别处理。 3、算出以该行为坐标轴,坐标轴上,每个由F组成的矩形的高度,与1506的区别是,1506中每个矩形高度已知。 4、按照150...

Cherrychan2014的博客 141

HDU 1505 City Game(DP)

此题类似于HDU1505。       我们可将连续“F”看做是楼高,这样像1505题一样处理n层就可以了。复杂度O(nmlogm)。       #include #include #include #include #include #include #include #include #include #include #include #include usin

ACMiao的博客 444

hdu 1505 City Game(DP)

City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4646    Accepted Submission(s): 1976 Problem Description Bob is a strateg

ACway的专栏 3791

hdu 1505 dp City Game

嗯。主要就是记录一行比a[i]的高度高的相邻的长度。然后比较面积最大的。 那么,怎么记录。。。 如果,a[i]左边第一个的高度比a[i]高,那么,搜寻比a[i-1]高的、、、依次类推。若果,a[i-1] 而当到a[i+1]的时候,如果a[i+1] 同理,右边一样这样计算与a[i]相邻的长度。 这时候,就用到了DP的思想。即所有的计算不会重复。计算过一遍之后,记录起来,用的时候,直接拿出来

夜月 560
上一篇: 【DP】 hdu1506 Largest Rectangle in a Histogram
下一篇: 【转】背包问题总结(0-1背包+完全背包+多重背包)
ACM_Ted
博客等级 码龄15年 122粉丝 208原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值