HDU 1505 City Game (hdu1506 dp二维加强版)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
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
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
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int d[][];
int l[];
int r[];
int main()
{
int n;
cin>>n;
while(n--)
{
int a,b;
cin>>a>>b;
// memset(d,0,sizeof(d));
for(int i=; i<a; i++)
{
for(int j=; j<b; j++)
{
char c[];
cin>>c;
if(c[]=='F')
d[i][j]=;
else
d[i][j]=;
}
}
/*
0 1 1 1 1 1 0 1 1 1 1 1
1 1 1 1 1 1 (F=1,R=0,方便求和) 1 2 2 2 2 2
0 0 0 1 1 1 转化完就是右边矩阵 0 0 0 3 3 3
1 1 1 1 1 1 1 1 1 4 4 4
1 1 1 1 1 1 2 2 2 5 5 5
*/
for(int i=; i<a; i++)
{
for(int j=; j<b; j++)
{
if(d[i][j]!=)
d[i][j]=d[i-][j]+;
}
}
/* printf("--------------->\n");
for(int i=0; i<a; i++){
for(int j=0; j<b; j++)
printf("%d ",d[i][j]);
printf("\n");
} printf("----------------->\n");*/
int max=;
for(int i=; i<a; i++){
for(int j=; j<b; j++){
l[j]=j;
while(l[j]>&&d[i][l[j]-]>=d[i][j])
l[j]=l[l[j]-];
}
for(int j=b-; j>-; j--){
r[j]=j;
while(r[j]<b-&&d[i][r[j]+]>=d[i][j])
r[j]=r[r[j]+];
}
for(int j=; j<b; j++)
if(max<((r[j]-l[j]+)*d[i][j]))
max=((r[j]-l[j]+)*d[i][j]);
}
cout<<max*<<endl;
}
return ;
}
HDU 1505 City Game (hdu1506 dp二维加强版)的更多相关文章
- HDU 1505 City Game【DP】
题意:是二维的1506,即在1506的基础上,再加一个for循环,即从第一行到最后一行再扫一遍--- 自己写的时候,输入的方法不对---发现输不出结果,后来看了别人的----@_@发现是将字母和空格当 ...
- hdu 1505 City Game (hdu1506加强版)
# include <stdio.h> # include <algorithm> # include <string.h> # include <iostr ...
- HDU 1505 City Game(DP)
City Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HDU 2159 FATE (DP 二维费用背包)
题目链接 题意 : 中文题不详述. 思路 : 二维背包,dp[i][h]表示当前忍耐值为i的情况下,杀了h个怪得到的最大经验值,状态转移方程: dp[i][h] = max(dp[i][h],dp[i ...
- 经典DP 二维换一维
HDU 1024 Max Sum Plus Plus // dp[i][j] = max(dp[i][j-1], dp[i-1][t]) + num[j] // pre[j-1] 存放dp[i-1] ...
- hdu6078 Wavel Sequence dp+二维树状数组
//#pragma comment(linker, "/STACK:102400000,102400000") /** 题目:hdu6078 Wavel Sequence 链接:h ...
- HDU 2888:Check Corners(二维RMQ)
http://acm.hdu.edu.cn/showproblem.php?pid=2888 题意:给出一个n*m的矩阵,还有q个询问,对于每个询问有一对(x1,y1)和(x2,y2),求这个子矩阵中 ...
- dp --- 二维dp + 最大上升子序列
<传送门> 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 74477 Accepted: 27574 ...
- codeforces 597div2 F. Daniel and Spring Cleaning(数位dp+二维容斥)
题目链接:https://codeforces.com/contest/1245/problem/F 题意:给定一个区间(L,R),a.b两个数都是属于区间内的数,求满足 a + b = a ^ b ...
随机推荐
- [C#基础]说说委托+=和-=的那些事
写在前面 为什么会突然想说说委托?原因吗,起于一个同事的想法,昨天下班的路上一直在想这个问题,如果给委托注册多个方法,会不会都执行呢?为了一探究性,就弄了个demo研究下. += 大家都知道委托都继承 ...
- WCF入门 (13)
前言 公司略无聊,周三前同事推荐跳槽,于是会去更新了一下简历,突然发现,快一年了,我竟然想不出我可以往简历上添加点什么值得自豪的东西.下午和小伙伴聊了一会天,他告诉我,可以往简历上写上“英语口语水平有 ...
- Oracle 索引
索引是建立在数据库表中的某些列的上面,是与表关联的,可提供快速访问数据方式,但会影响增删改的效率:常用类型(按逻辑分类):单列索引和组合索引.唯一索引和非唯一索引. 什么时候要创建索引 (1)在经常需 ...
- 传智168期JavaEE就业班 day02-css
* 课程回顾: * HTML语言 * HTML的简介 超文本标记语言. * 是网页最基础的语言. * 都是由标签所组成的. * HTML的基本格式 <html> <head> ...
- G-nav-04
'use strict';define([ 'jquery'], function($) { var nav = { init : function() { $("#burger-menu& ...
- array,vertor,arraylist,hashable,hashmap等几个易混淆概念的区别
Array可以存放Object和基本数据类型,但创建时必须指定数组的大小,并不能再改变, Vertor是放的Object. Vertor一维,Hashmap/Hashtabe二维: Vertor/Ar ...
- 【Aizu 2305】Beautiful Currency
题 题意 给你n个货币价格,然后通过调整一些货币的大小,使得所有比自己小的货币都是该货币的约数,调整前第 i 货币为a,调整后为b 那么变化率为 ri=|a-b|/a ,总变化率为max(ri).求最 ...
- 从svn服务器自动同步到另一台服务器
需求场景 A commit B post-commit C (workstation) --------------> (svn server) ---------------------> ...
- MyEclipse2014中SVN的使用方法
MyEclipse中的SVN操作手册 1.导入项目 点击工具栏上的[File-Import],进入下图 (如果你的对话框中没有SVN这一条目,可能是因为你没有安装SVN插件,请安装完成后,在看这篇博客 ...
- Android实战_来电拦截专家
1 项目演示: 2 代码演示: 1)MainActivity类代码: MainActivity类代码: package com.example.phoneinteceptor_one;import j ...