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 ...
随机推荐
- linux用户管理命令
关键字 useradd passwd who w uptime 1.useradd添加用户命令 useradd 用户名 passwd 用户名 (设置密码) 2.userdel 删除用户 userdel ...
- Servlet获取简单验证码
package com.helloweenvsfei.servlet; import java.awt.Color; import java.awt.Font; import java.awt.Gra ...
- new-nav-css
header:before, header:after ,.navigation:before, .navigation:after,.nav-row:before, .nav-row:after,. ...
- Mysql-函数coalesce-查询为空设置默认值
coalesce(字段,默认值) select coalesce(title,'liu') from a
- 【poj2773】 Happy 2006
http://poj.org/problem?id=2773 (题目链接) 题意 给出两个数m,k,要求求出从1开始与m互质的第k个数. Solution 数据范围很大,直接模拟显然是不行的,我们需要 ...
- GridView动态添加列之后,导致PostBack(回发)页面数据丢失问题解决
直入主题,首先声明,这个问题是无法解决的,特此在这说明 一.如何动态添加列,如下: 在页面重写OnInit事件,至于为什么要在这个事件写,根据页面的声明周期和经验可知(不用去别的地方找了,这个我找了之 ...
- HDU1242 Rescue
Rescue Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Description A ...
- linux中防CC攻击两种实现方法(转)
CC攻击就是说攻击者利用服务器或代理服务器指向被攻击的主机,然后模仿DDOS,和伪装方法网站,这种CC主要是用来攻击页面的,导致系统性能用完而主机挂掉了,下面我们来看linux中防CC攻击方法. 什么 ...
- mq安装参考
CentOS 6.2 64bit 安装erlang及RabbitMQ Server 1.操作系统环境(CentOS 6.2 64bit) [root@leekwen ~]# cat /etc/issu ...
- Note:JSON
JSON是JavaScript的原生格式,意味着在JavaScript中处理JSON数据不需要特殊的API或工具包,它是完全独立于语言的文本格式,可以把JavaScript对象中的一组对象转化为字符串 ...