UESTC--1271--Search gold(贪心)
Time Limit: 1000MS | Memory Limit: 65535KB | 64bit IO Format: %lld & %llu |
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
#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(贪心)的更多相关文章
- CDOJ 1271 Search gold
简单DP.dp[i][j]表示走到这格的最大金钱数. #include<cstdio> #include<cstring> #include<cmath> #inc ...
- Search gold(dp)
Search gold Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Subm ...
- 集束搜索beam search和贪心搜索greedy search
贪心搜索(greedy search) 贪心搜索最为简单,直接选择每个输出的最大概率,直到出现终结符或最大句子长度. 集束搜索(beam search) 集束搜索可以认为是维特比算法的贪心形式,在维特 ...
- 【动态规划】CDOJ1271 Search gold
方格取数. 但由于题意说金币数<0就死了,就不能继续转移. #include<cstdio> #include<algorithm> #include<cstrin ...
- beam search 和 greedy search
贪心搜索(greedy search): 贪心搜索最为简单,直接选择每个输出的最大概率,直到出现终结符或最大句子长度. 集束搜索(beam search): 集束搜索可以认为是维特比算法的贪心形式,在 ...
- 第七届ACM趣味程序设计竞赛第四场(正式赛) 题解
Final Pan's prime numbers 题目连接: http://acm.uestc.edu.cn/#/problem/show/1272 题意 给你n,要求你在[4,n]范围内找到一个最 ...
- Andrew Ng机器学习公开课笔记 -- Regularization and Model Selection
网易公开课,第10,11课 notes,http://cs229.stanford.edu/notes/cs229-notes5.pdf Model Selection 首先需要解决的问题是,模型 ...
- 《Sequence Models》课堂笔记
Lesson 5 Sequence Models 这篇文章其实是 Coursera 上吴恩达老师的深度学习专业课程的第五门课程的课程笔记. 参考了其他人的笔记继续归纳的. 符号定义 假如我们想要建立一 ...
- deeplearning.ai 序列模型 Week 3 Sequence models & Attention mechanism
1. 基础模型 A. Sequence to sequence model:机器翻译.语音识别.(1. Sutskever et. al., 2014. Sequence to sequence le ...
随机推荐
- Centos 6 搭建邮箱服务器教程
Centos 6 搭建邮箱服务器主要是是包括了Postfix, Dovecot和 MySQL了,下文我们详细的为各位介绍Centos 6 搭建邮箱服务器教程(Postfix, Dovecot和 MyS ...
- JqGrid saveRow方法报404错误
TCX_1807工艺配置/检测项配置页面为jqgrid可编辑页面,使用的脚本为 ){ jQuery('#gridList').saveRow(lastId, true);//保存上一个修改的单元行 } ...
- SVG剪裁路径和遮罩jQuery幻灯片
SVG剪裁路径和遮罩jQuery幻灯片是一款基于SVG clipPath和mask遮罩元素实现的网站动画幻灯片代码特效. 在线演示本地下载
- 修改织梦data目录名
1.修改include目录下的common.inc.php这个文件.打开文件,找到第24行: define('DEDEDATA', DEDEROOT.'/data'); 把data修改成为您要改的目录 ...
- mysql和eclipse连接jdbc驱动配置
环境Windows10 eclipse 64位 MySQL 一:资料准备 (MySQL,eclipse下载安装不在赘述) 配置好MySQL环境后 下载jdbc地址http://dev.mysql.co ...
- HTTP获取信息的四种方式
HTTP 从网络获取信息的四种方式 GET GET指代你在浏览器中输入网址,浏览网站时做的事.例如,我们使用 http://www.baidu.com 的时候,可以将GET想象成他说:"hi ...
- [ Java ] String 轉型 ArrayList
Lambda 對我而言一很像天書 這個行 Java code 讓我開始有點些微有 Lambda 感覺 https://stackoverflow.com/questions/10706721/conv ...
- 【Oracle】管理还原数据(undo)
1. 查看undo相关参数 SYS@LGR> show parameter undo NAME TYPE VALUE ------------------------------------ - ...
- VHDL之conversion function
VHDL Type Cast and Conversion Functions **In ASIC design, do NEVER use integer or natural for signal ...
- java学习笔记3——异或
异或原理: 转换两个字符或数为2进制的ASCII码,再按位异或,即 0001 0001 ---> 0000 0000 0000 ---> 0000 0001 0000 ---> 00 ...