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. ROS-tutorials-launch-查看日志

    前言:launch文件的作用是一次可以启动多个节点. 1.新建launch文件 在chapter2_tutorials包下新建launch文件夹,并在launch文件夹下新建chapter2.laun ...

  2. guice基本使用,三种注入方式(二)

    guice提供了强大的注入方式. 1.属性注入 2.构造器注入 3.set方式注入 1.属性注入: package com.ming.user.test; import com.google.inje ...

  3. js原生_获取url键值对

    思路: 1.先对url进行处理,获取 ?后的字符串 postid=10457794&actiontip=保存修改成功') 2. 字符串通过&标识,不同参数转为数组 ["pos ...

  4. 利用JavaScript的%读分秒

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  5. 算法 之 3n+1问题

    卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反复砍下去,最后一定在某一步得到n=1.卡拉兹在1950年的世界数 ...

  6. spring过滤器篇

    CharacterEncodingFilter spring的web包下的一个过滤器,用于设置程序的字符编码,它有两个参数encoding和forceEncoding. encoding:字符集,将过 ...

  7. 推荐一款能支持国密SM2浏览器——密信浏览器

    密信浏览器( MeSince Browser )是基于Chromium开源项目开发的国密安全浏览器,支持国密算法和国密SSL证书,同时也支持国际算法及全球信任SSL证书:密信浏览器使用界面清新,干净. ...

  8. 【BZOJ3451】Tyvj1953 Normal - 点分治+FFT

    题目来源:NOI2019模拟测试赛(七) 非原题面,题意有略微区别 题意: 吐槽: 心态崩了. 好不容易场上想出一题正解,写了三个小时结果写了个假的点分治,卡成$O(n^2)$ 我退役吧. 题解: 原 ...

  9. javascript的带操作符的赋值运算

    看犀牛书发现的问题 下面两个表达式 表达式一 data[i++] *= 2; 表达式二 data[i++] = data[i++] * 2;   var data = [7,8,9]; var i = ...

  10. 洛谷P1739 表达式括号匹配

    题目描述 假设一个表达式有英文字母(小写).运算符(+,-,*,/)和左右小(圆)括号构成,以"@"作为表达式的结束符.请编写一个程序检查表达式中的左右圆括号是否匹配,若匹配,则返 ...