首页 > 其他分享 >UESTC 1271 Search gold

UESTC 1271 Search gold

时间:2022-11-09 20:07:48浏览次数:38  
标签:Search gold int 1271 cave max 100 include


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


这个一看就是dp,只要注意边界问题就好了。

#include<iostream>  
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
const int maxn = 1e3 + 5;
int T, n, m, f[maxn][maxn], a[maxn][maxn];

int main(){
//scanf("%d", &T);
while (~scanf("%d%d", &n, &m))
{
n++; m++;
memset(f, -1, sizeof(f));
for (int i = 2; i <= n;i++)
for (int j = 2; j <= m; j++) scanf("%d", &a[i][j]);
f[2][2] = a[2][2];
int ans = 0;
for (int i = 2; i <= n; i++)
{
for (int j = 2; j <= m; j++)
{
if (f[i - 1][j] >= 0) f[i][j] = max(f[i][j], f[i - 1][j] + a[i][j]);
if (f[i][j - 1] >= 0) f[i][j] = max(f[i][j], f[i][j - 1] + a[i][j]);
if (f[i - 1][j - 2] >= 0) f[i][j] = max(f[i][j], f[i - 1][j - 2] + a[i][j]);
if (f[i - 2][j - 1] >= 0) f[i][j] = max(f[i][j], f[i - 2][j - 1] + a[i][j]);
ans = max(ans, f[i][j]);
}
}
printf("%d\n", ans);
}
return 0;
}



标签:Search,gold,int,1271,cave,max,100,include
From: https://blog.51cto.com/u_15870896/5838687

相关文章

  • ElasticSearch:集成IK分词器以及基本使用
    IK分词器的简单介绍把一段中文划分成一个个的关键字,我们在搜索时候会把自己的语句进行分词,会把数据库中或者索引库中的数据进行分词,然后进行一个匹配操作,默认的中文分......
  • ElasticSearch Java API之索引操作
    背景:​​ElasticSearchJava客户端连接ElasticSearch​​以这篇博客为基础​​ElasticSearch:简单介绍以及使用Docker部署ElasticSearch和Kibana​​这篇博客简单部署了E......
  • ElasticSearch Java API之文档操作
    文档Document简单介绍被索引的一条数据,索引的基本信息单元,以JSON格式来表示。比如:你可以拥有某一个客户的文档,某一个产品的一个文档,当然,也可以拥有某个订单的一个文档。文档......
  • ElasticSearch Java 客户端连接ElasticSearch
    背景:​​ElasticSearch:简单介绍以及使用Docker部署ElasticSearch和Kibana​​这篇博客简单部署了ElasticSearchElasticSearch客户端特征所有ElasticsearchAPI的强类......
  • 第四十一章 构建数据库应用程序 - 带有CSP Search标签的CSP搜索页面
    第四十一章构建数据库应用程序-带有<CSP:Search>标签的CSP搜索页面search标记创建一个通用搜索页面,可以将其与绑定表单一起使用以执行查找操作。应用程序用户可以从......
  • Elastaticsearch 集群部署
    系统Ubuntu16.04Elastaticsearch5.6.9Kibana5.6.9官网地址https://www.elastic.co/products/elasticsearch主机名称IPes-n1192.168.175.76......
  • Elasticsearch调优
    设计阶段调优1.根据业务增量需求,采取基于日期模板创建索引,通过rolloverAPI滚动索引;2.使用别名进行索引管理;3.每条凌晨定时对索引做force_merge操作,以释放空间。4.采取冷......
  • Computer Vision_33_SIFT:Improving Bag-of-Features for Large Scale Image Search—
    此部分是计算机视觉部分,主要侧重在底层特征提取,视频分析,跟踪,目标检测和识别方面等方面。对于自己不太熟悉的领域比如摄像机标定和立体视觉,仅仅列出上google上引用次数比较多......
  • ASP .NET Core 使用 Serilog记录日志并输出至ElasticSearch
    Serilog添加ES配置服务端Elasticsearch+Kibana的部署参考这篇博客,版本都是当前最新版本8.5.0Serilog相关文档参考这篇博客新建一个ASP.NETCoreWeb项目,添加以下Neget......
  • VulnHub-GoldenEye-1-Walkthrough
    靶机地址:https://www.vulnhub.com/entry/goldeneye-1,240/下载成功过后使用虚拟机打开需要注意:靶机和kail的网络适配器需要一致,不然会扫描不出来,这里我使用的的nat模式......