Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu

Submit
Status

Description

Dreams of finding lost treasure almost came true recently. A new machine called 'The Revealer' has been invented and it has been used to detect gold which has been buried in the ground. The machine was used in a cave near the seashore where – it is said
– pirates used to hide gold. The pirates would often bury gold in the cave and then fail to collect it. Armed with the new machine, a search party went into the cave hoping to find buried treasure. The leader of the party was examining the soil near the entrance
to the cave when the machine showed that there was gold under the ground. Very excited, the party dug a hole two feel deep. They finally found a small gold coin which was almost worthless. The party then searched the whole cave thoroughly but did not find
anything except an empty tin trunk. In spite of this, many people are confident that 'The Revealer' may reveal something of value fairly soon.

So,now you are in the point$(1,1)$ and initially you have 0 gold.In the $n$*$m$ grid there are some traps and you will lose gold.If your gold is not enough you will be die.And there are some treasure and you will get gold.If you are in the point(x,y),you
can only walk to point $(x+1,y),(x,y+1),(x+1,y+2)$and$(x+2,y+1)$.Of course you can not walk out of the grid.Tell me how many gold you can get most in the trip.

It`s guarantee that$ (1,1)$is not a trap;

Input

first come $2$ integers, $n,m$($1≤n≤1000$,$1≤m≤1000$)

Then follows $n$ lines with $m$ numbers $ a_{ij} $

$(-100<=a_{ij}<=100) $

the number in the grid means the gold you will get or lose.

Output

print how many gold you can get most.

Sample Input

3 3

1 1 1

1 -5 1

1 1 1


3 3

1 -100 -100

-100 -100 -100

-100 -100 -100

Sample Output

5


1

Hint

Source

第七届ACM趣味程序设计竞赛第四场(正式赛)

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int dx[4] = {1,0,1,2};
int dy[4] = {0,1,2,1};
int a[1005][1005];
int dp[1005][1005];
int m,n;
int main()
{
memset(dp,-1,sizeof(dp));
scanf("%d %d",&n,&m);
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++)
scanf("%d",&a[i][j]);
dp[1][1] = a[1][1];
int ans = -1;
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++)
{
if(dp[i][j] < 0)
continue;
ans=max(dp[i][j],ans);
for(int k=0;k<4;k++)
{
int x = i + dx[k];
int y = j + dy[k];
if(x<=0||x>n||y<=0||y>m)
continue;
dp[x][y] = max(dp[i][j] + a[x][y],dp[x][y]);
}
}
printf("%d\n",ans);
return 0;
}

UESTC--1271--Search gold(贪心)的更多相关文章

  1. CDOJ 1271 Search gold

    简单DP.dp[i][j]表示走到这格的最大金钱数. #include<cstdio> #include<cstring> #include<cmath> #inc ...

  2. Search gold(dp)

    Search gold Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Subm ...

  3. 集束搜索beam search和贪心搜索greedy search

    贪心搜索(greedy search) 贪心搜索最为简单,直接选择每个输出的最大概率,直到出现终结符或最大句子长度. 集束搜索(beam search) 集束搜索可以认为是维特比算法的贪心形式,在维特 ...

  4. 【动态规划】CDOJ1271 Search gold

    方格取数. 但由于题意说金币数<0就死了,就不能继续转移. #include<cstdio> #include<algorithm> #include<cstrin ...

  5. beam search 和 greedy search

    贪心搜索(greedy search): 贪心搜索最为简单,直接选择每个输出的最大概率,直到出现终结符或最大句子长度. 集束搜索(beam search): 集束搜索可以认为是维特比算法的贪心形式,在 ...

  6. 第七届ACM趣味程序设计竞赛第四场(正式赛) 题解

    Final Pan's prime numbers 题目连接: http://acm.uestc.edu.cn/#/problem/show/1272 题意 给你n,要求你在[4,n]范围内找到一个最 ...

  7. Andrew Ng机器学习公开课笔记 -- Regularization and Model Selection

    网易公开课,第10,11课 notes,http://cs229.stanford.edu/notes/cs229-notes5.pdf   Model Selection 首先需要解决的问题是,模型 ...

  8. 《Sequence Models》课堂笔记

    Lesson 5 Sequence Models 这篇文章其实是 Coursera 上吴恩达老师的深度学习专业课程的第五门课程的课程笔记. 参考了其他人的笔记继续归纳的. 符号定义 假如我们想要建立一 ...

  9. deeplearning.ai 序列模型 Week 3 Sequence models & Attention mechanism

    1. 基础模型 A. Sequence to sequence model:机器翻译.语音识别.(1. Sutskever et. al., 2014. Sequence to sequence le ...

随机推荐

  1. Solr.NET快速入门(三)【高亮显示】

    此功能会"高亮显示"匹配查询的字词(通常使用标记),包括匹配字词周围的文字片段. 要启用高亮显示,请包括HighlightingParameters QueryOptions对象, ...

  2. 使用C#正则表达式获取必应每日图片地址

    微软的Bing搜索引擎首页每天都会提供了一些有趣的图片,下面使用正则表达式获取图片的地址,不管是在手机app还是在网站上都是很好的图片素材,而且每天更新,非常不错. 首先访问微软的API,该地址返回的 ...

  3. mac 下安装 mariadb

    通过brew 安装: brew install mariadb 初始化数据库 cd /usr/local/Cellar/mariadb/10.0.10/scripts mysql_install_db ...

  4. Linux强行踢用户

    首先who执行查看有几个终端在链接使用系统.如要踢出tty2 方法1: pkill -9 -t tty2 方法2: fuser -k /dev/tty2 fuser 指令 用途 使用文件或文件结构识别 ...

  5. RabbitMQ学习之Flow Control

    当RabbitMQ发布消息速度快于消费速度或者系统资源不足时,RabbitMQ将降低或阻断发布消息速度,以免服务器资源饱满而宕机,可以通过rabbitmqctl和web管理页面查看连接的状态为flow ...

  6. 【seo】title / robots / description / canonical

    1.title title,就是浏览器上显示的那些内容,不仅用户能看到,也能被搜索引擎检索到(搜索引擎在抓取网页时,最先读取的就是网页标题,所以title是否正确设置极其重要. 1)title一般不超 ...

  7. 图片放大不失真软件PhotoZoom的工具栏

    PhotoZoom是一款极其简单的图片无损放大工具,简单几即可渲染出完美的放大照片,呈现无与伦比的画质效果.虽然简单,菜单和面板的功能很少,但却是设计师的必备神器,因为其简单易用性,它的软件菜单命令和 ...

  8. Mysql 5.7 for windows 免安装版(解压版)安装和配置

    网上写的不近详细,这里重新整理下. 准备: 1.windows操作系统 2.mysql 的解压版压缩文件 第一步: 解压mysql的压缩包到你的安装目录,因为是虚拟机,这里我就安装在C盘下:C:\my ...

  9. linux 性能分析与优化

    一.影响Linux服务器性能的因素 1.操作系统级 (CPU 内存 磁盘I/O性能 网络带宽) 2.程序应用级 二.系统性能评估标准   好  坏 极差 cpu user% +sys% <70% ...

  10. WSDL详解(一)

    WSDL文档使用web服务描述语言来定义服务. 文档包括逻辑(抽象)部分和具体部分. 抽象部分用于定义独立于实现的数据类型和消息,具体部分定义一个endpoint如何实现一个可以与外界进行交互的服务. ...