【动态规划】CDOJ1271 Search gold

方格取数。
但由于题意说金币数<0就死了,就不能继续转移。
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int dx[]={0,1,1,2},dy[]={1,0,2,1};
int n,m,a[1010][1010],f[1010][1010];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
scanf("%d",&a[i][j]);
}
}
memset(f,0xaf,sizeof(f));
f[1][1]=a[1][1];
int ans=f[1][1];
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
for(int k=0;k<4;++k){
int tx=i+dx[k],ty=j+dy[k];
if(tx<=n && ty<=m && f[i][j]+a[tx][ty]>=0/*根据题意,死了就不行啦!*/){
f[tx][ty]=max(f[tx][ty],f[i][j]+a[tx][ty]);
}
}
ans=max(ans,f[i][j]);
}
}
printf("%d\n",ans);
return 0;
}
【动态规划】CDOJ1271 Search gold的更多相关文章
- Search gold(dp)
Search gold Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Subm ...
- CDOJ 1271 Search gold
简单DP.dp[i][j]表示走到这格的最大金钱数. #include<cstdio> #include<cstring> #include<cmath> #inc ...
- UESTC--1271--Search gold(贪心)
Search gold Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu Submit Sta ...
- 第七届ACM趣味程序设计竞赛第四场(正式赛) 题解
Final Pan's prime numbers 题目连接: http://acm.uestc.edu.cn/#/problem/show/1272 题意 给你n,要求你在[4,n]范围内找到一个最 ...
- LeetCode之“动态规划”:Unique Binary Search Trees && Unique Binary Search Trees II
1. Unique Binary Search Trees 题目链接 题目要求: Given n, how many structurally unique BST's (binary search ...
- Unique Binary Search Trees I&&II(II思路很棒)——动态规划(II没理解)
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For exa ...
- LEETCODE —— Unique Binary Search Trees [动态规划]
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- 【POJ3280/洛谷2890】[Usaco2007 Open Gold]Cheapest Palindrome(动态规划)
题目: POJ3280 洛谷2980 分析: 首先,考虑只可以加字的情况 设\(s[i]\)表示第\(i\)个字符,\(add[i]\)表示加上一个字母\(i\)的花费,\(dp[i][j]\)表示把 ...
- [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...
随机推荐
- Android中的异常情况
1.setText()方法中,如果参数是int类型,Android会把它当做是一个id查找,报以下异常,因此解决办法就是将参数转化为String类型 如:setText(num) è setText( ...
- Python3 高阶函数
高阶函数 (满足其一就是:(1)一个函数名作为另一个函数的形参:(2)返回值包含函数名;不修改函数的调用方式) 1.一个函数名作为另一个函数的形参 输出结果: 2.返回值包含函数名;不修改函数的 输出 ...
- 使用makecontext实现用户线程【转】
转自:http://blog.csdn.net/cyberlabs/article/details/6920138 使用makecontext实现用户线程 现代Unix系统都在ucontext.h中提 ...
- 大原則 研讀 spec 與 code 的 心得
最近在研究 stm32f429i-disc0 的 device tree source code, 並且 參造 Devicetree Specification Release 0.1, 在 dts ...
- python基础===pendulum '''Python datetimes made easy.'''
https://pypi.python.org/pypi/pendulum Pendulum的一大优势是内嵌式取代Python的datetime类,可以轻易地将它整合进已有代码,并且只在需要的时候才进 ...
- centos_7.1.1503_src_6
http://vault.centos.org/7.1.1503/os/Source/SPackages/ perl-Test-MockObject-1.20120301-3.el7.src.rpm ...
- HDU 4305 Lightning Matrix Tree定理
题目链接:https://vjudge.net/problem/HDU-4305 解法:首先是根据两点的距离不大于R,而且中间没有点建立一个图.之后就是求生成树计数了. Matrix-Tree定理(K ...
- Redis错误:jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password is set
原文链接:http://blog.csdn.net/rchm8519/article/details/48347797 redis.clients.util.Pool.getResource(Pool ...
- iframe弹出框js ie6下存在bug
ie6的iframe在第一次加载的显示不出来,显示空白,但是很奇怪,刷新就可以正常显示了,一开始以为这只是IE6下iframe加载的bug,但是最后结果发现这是ie6下javascript延迟加载出现 ...
- Fastcgi协议定义解释与说明
1 响应格式如(十六进制方式显示) 序列 0 1 2 3 4 5 6 7 ... 数值 01 06 00 01 01 1D 03 00... 序列0(值01)为version,固定取1即可序列1(值0 ...