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. JS form 表单收集 数据 formSerialize

    做后台系统的时候通常会用到form表单来做数据采集:每次一个字段一个字段的去收集就会很麻烦,网站也有form.js插件可以进行表单收集,并封装成一个对象,通过ajax方法传到后台:现在介绍一种直觉采集 ...

  2. 【转】window 安装redis服务、卸载redis服务和启动redis服务

    1.安装redis服务 redis-install.bat 1 echo install redis-server23 D:\redis\redis-server.exe --service-inst ...

  3. javascript 将单词首字母大写,其余小写

    // 1 别人写的,我拿来参考了一下 function titleCase(str) { var array = str.toLowerCase().split(" "); for ...

  4. GoogleMap 获取自己的数字证书API key的步骤

    http://dreamylights.blog.51cto.com/1163218/1360759 1. 进入到Google APIs Console页面 https://code.google.c ...

  5. R 连接DB2数据库,并制作词图

    #写在前面的话:此教程主要是用R连接了DB2数据库,并进行文本分析,制作了词图 #教程为markdown编写 ---title: "网站留言分析"output: html_docu ...

  6. mysql简单语句

    创建名为user的数据库: create database user; 显示所有数据库: show databases; 选择名为user的数据库: use user; 显示所有表: show tab ...

  7. C# model代码生成器

    using System.Collections.Generic; using System.Text; public class Class1 { //传递 1.表名 2.列名 3.类型 publi ...

  8. Dynamics CRM 使用 Profiler 来做debug

    首先,我们需要install Profiler 我们选中一个plugin, 并且选择start Profilling 然后我们选择Persist to Entity 然后我们执行trigger这个pl ...

  9. 动态给某一个元素添加active

    <li class="one_data" data-id='+ navGroup.self_first_nav[i].id +'><a  href='+ navG ...

  10. Flex元素布局规则总结,以及布局和容器

    一.Flex中的元素分类从功能层面可以把Flex中的元素分为组件(Components)和容器(Containers)两大类:组件 - 是指那类具有明确交互或数据展示功能的元素,例如Button.Ch ...