UESTC - 1271 Search gold (DP)
2016-03-23 13:52
447 查看
UESTC
- 1271
Search gold
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
aij
(−100<=aij<=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
//题意:如果你在位置(x,y),你下一步只能向(x+1,y),(x,y+1),(x+1,y+2),(x+2,y+1)这四个方向走。
给你一个n*m的矩阵,每个位置都有一个宝藏,正的表示你可以获利那么多的宝藏,
负的表示你要消耗这么多的宝藏,当你的宝藏为负的时候,你就不能再继续向前了。
问在你探寻宝藏的过程中,你获得的宝藏的值最大是多少?
- 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
aij
(−100<=aij<=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
//题意:如果你在位置(x,y),你下一步只能向(x+1,y),(x,y+1),(x+1,y+2),(x+2,y+1)这四个方向走。
给你一个n*m的矩阵,每个位置都有一个宝藏,正的表示你可以获利那么多的宝藏,
负的表示你要消耗这么多的宝藏,当你的宝藏为负的时候,你就不能再继续向前了。
问在你探寻宝藏的过程中,你获得的宝藏的值最大是多少?
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<iostream> #define INF 0x3f3f3f3f #define ull unsingned long long #define ll long long #define IN __int64 #define N 1010 #define M 1000000007 using namespace std; int map ,dp ; int dx[4]={1,0,1,2}; int dy[4]={0,1,2,1}; int main() { int t,n,m; int i,j,k; int x,y; while(scanf("%d%d",&n,&m)!=EOF) { memset(dp,-1,sizeof(dp)); memset(map,0,sizeof(map)); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { scanf("%d",&map[i][j]); } } int mm=0; dp[1][1]=map[1][1]; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { if(dp[i][j]<0) continue; mm=max(dp[i][j],mm); for(k=0;k<4;k++) { x=i+dx[k]; y=j+dy[k]; if(x<1||x>n||y<1||y>m) continue; dp[x][y]=max(dp[i][j]+map[x][y],dp[x][y]); } } } printf("%d\n",mm); } return 0; }
相关文章推荐
- RequireJS禁止缓存
- 信号发送(sigqueue)和接收(sigaction)
- iOS开发UI篇—CAlayer(自定义layer)
- 关于UITableView — cell上点击按钮变换
- 演练:从头开始创建 MSBuild 项目文件
- NSNumber和NSValue
- MSDN中对MSBuild的解释页
- EasyUI前端框架控件案例
- 16其他UI内容
- 15.UIDynamic 物理引擎
- MSBuild入门
- 开发UI控件时遇到的问题(类似于苹果Assistive Touch)
- [转]MSBuild的简单介绍与使用
- ios的手势操作之UIGestureRecognizer浅析
- UIView上添加了一个按钮和一个单击手势的事件相应,互相不影响的处理方法。。
- juery给所有ID属性相同的div绑定一个事件
- request.getAttribute()与request.getParameter() 方法区别
- 关于UIImagePickerController 被dismiss 后 屏幕顶部弹出红条 的问题
- epoll 或者 kqueue 的原理是什么?
- Day4.3--Android高级UI控件之ProgressBar的使用