UESTC--1271--Search gold(贪心)
2016-01-16 22:05
330 查看
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 $ 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趣味程序设计竞赛第四场(正式赛)
Time Limit: 1000MS | Memory Limit: 65535KB | 64bit IO Format: %lld & %llu |
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; }
相关文章推荐
- UI学习第06天
- getRequestDispatcher()与sendRedirect()的区别
- 关于UIWindow的一点儿思考
- iOS - UICollectionView学习
- UITextFielddelegate委托方法注释
- UESTC Memory 1262 (打表&暴力模拟)
- UESTC第七届ACM趣味程序设计竞赛第四场(正式赛)
- 【SSH网上商城】Incorrect datetime value: '' for column 'pdate' at row 1
- UESTC--1272--Final Pan's prime numbers(水题)
- 内核发送uevent的API,用户空间解析uevent
- UESTC--1272--Final Pan's prime numbers(水题)
- 批处理文件:实现将写好的Android Uiautomator工程打包成jar包放到手机中执行
- UI小结.(一)
- UESTC--1269--ZhangYu Speech(模拟)
- UESTC--1269--ZhangYu Speech(模拟)
- UESTC--1265--宝贵资源(简单数学)
- UESTC--1265--宝贵资源(简单数学)
- UESTC--1264
- UESTC--1263--The Desire of Asuna(贪心)
- UESTC--1263--The Desire of Asuna(贪心)