【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 内附安装教程 立即下载

相关推荐

解决Visual C++2008安装失败,error 1935

重装系统后Visual C++没了,其他都能装上但VC2008会报这个error 1935。鉴于我把网上所有的解决方法排了一遍错,我也不知道是哪一步起效,所以就都放上来了。特别注意:报error 1935的错误原因可能不尽相同,比如我的报错开头为An error occurred,结尾为HRESULT:0x80070005。80070005 拒绝访问通常是权限问题,安装Visual C++无法写入文件夹或注册表(直接跳转第7步)

weixin_44427808的博客 1万+

【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

VirusTotal API密钥获取与Python实战:从注册到自动化威胁分析

在网络安全和自动化运维领域,API(应用程序编程接口)是实现系统间数据交互与功能集成的核心技术。其工作原理是通过预定义的协议和端点,允许程序化访问特定服务的数据与功能。对于安全工程师和威胁分析师而言,API的价值在于能够将手动、重复的安全操作(如文件扫描、情报查询)转化为自动化工作流,从而极大提升威胁检测与响应的效率。一个典型的应用场景是集成第三方威胁情报平台,以实现对可疑文件、URL或哈希值的批量与实时分析。本文聚焦于全球知名的威胁情报服务VirusTotal,详细解析其API密钥的注册流程、安全配置要点

weixin_28707739的博客 421

【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

使用ADS进行LNA低噪放设计的详细教程

详细介绍了通过ADS软件进行LNA设计的过程,从晶体管的选型到稳定性系数分析、再到输入输出端匹配,完整的讲解了低噪放的设计流程,可以使新手小白以及学习射频放大器的朋友可以快速的了解掌握ADS的使用方法和LNA的设计方法。

weixin_41831333的博客 3449

从零到一:手把手教你构建工业级Modbus转MQTT网关(STM32+ESP8266实战)

本文详细介绍了如何利用STM32和ESP8266构建工业级Modbus转MQTT网关,涵盖硬件选型、代码示例、协议转换及稳定性设计。重点解析Modbus RTU与MQTT协议对接阿里云物联网平台的实战步骤,确保数据可靠传输与长期稳定运行,为工业物联网应用提供完整解决方案。

u0v1w2x3的博客 685

HDU1505City Game(最大子矩阵)

题目链接:传送门 分析:题意大概就是要求一个由F和R构成的矩阵中,单单由F构成的最大矩阵 思路:运用到dp思想,但第一次做还是比较难想到,用一个dp数组记录高度,再用两个数组分别来表示某个点向左和向右延伸的最大宽度,最后再计算每块的面积就OK了 AC代码: #include&amp;lt;iostream&amp;gt; #include&amp;lt;cstring&amp;gt; using namespace std; i...

Stark_industry 303

用户画像标签维度_搭建电商平台用户画像标签体系

01 整体思路电商平台连接了卖家和买家两端,最终目的都是促进交易,从而追求更高的销售额。提高人货匹配度是促进交易的关键,而提高人货匹配度的关键就是“让买家找到想要的货物”。本文结合“人、货、场”理论模型,尝试建立电商平台的用户画像标签体系。02 三类标签用户在平台购物的整体流程可以概括为:进入平台、选择商品、下单付款。可以将该过程抽象为“人、货、场”。即用户通过什么途径进入什么商品的页面...

weixin_31668621的博客 1642

hdu - 1505 - City Game(dp / 单调栈)

题意:一个 M x N 矩阵,其中有些格子有障碍,求

无节操 1386

实战指南:如何用Frida绕过某梆加固的Anti-Frida检测(附完整脚本)

本文深入剖析了企业级加固方案中的Anti-Frida检测机制,并提供了实战对抗策略。通过分析基于文件系统、内存特征、行为及环境的多层次检测原理,文章详细介绍了如何定位检测逻辑、绕过maps文件扫描、对抗内存与行为特征检测,并附上了针对某梆加固的完整绕过脚本与系统化工程方案。

weixin_42527589的博客 600

YOLOv8_obb训练流程-原理解析[旋转目标检测理论篇]

本文主要介绍了YOLOv8旋转目标检测的流程,介绍了标签的解码、预测结果的解码,以及如何理解旋转角度等内容,还介绍旋转目标检测框的正样本选取及Loss计算。

ice 4732

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

ROS2 CANopen 使用教程

第一步是定义一个结构,用于保存有关接头和相关 CANopen 数据的信息。该结构是 CANopen 网络的基础,可确保存储所有相关数据并在需要时进行访问。

机器人控制与仿真应用 3691

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

HDU-1505-City Game

Linoy 1186

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

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

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

HDU 1505 City Game(DP)

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

Good morning,good afternoon and good night 1063

pscad IEEE标准系统搭建说明

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

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、付费专栏及课程。

余额充值