【动态规划】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 ...
随机推荐
- js_同步和异步
刚开始写js那会,对这一块是知之甚少,太多太多的知识不足,致使做什么都很艰难.现在工作也有段时间了,知识也有了点积累, 写点什么分享一下. 同步和异步?这个问题是在使用ajax请求后台数据的时候出现的 ...
- perl6中字符串字母编历
use v6; my $input = prompt '输入字符串:'; for $input.words -> $word { say $word; } for $input.comb -&g ...
- 利用itext将html转为pdf
亲测代码没有问题,需要注意细节已经标注:需要jar包:iText-2.0.8.jar:core-renderer-R8.jar: core-renderer-R8.jar下载地址:http://cen ...
- 【Python问题解决】关于解决python3.x无法使用PIL库的解决方法
因为PIL库目前只更新到python2.x,故python3.x直接安装PIL库会找不到版本.但是python3.x有一个新的库,可以提供和PIL差不多的功能,也就是pillow库. 本人使用的是py ...
- 配置连接的IP、端口、以及相应的数据库
解压后里面有:lib 源文件 .examples 例子.test测试 将lib目录拷贝到你的项目中,就可以开始你的predis操作了. //使用autoload加载相关库,这边重点就是为了requir ...
- ifa_local 和 ifa_address
ifa_local 和 ifa_address区别联系: 1. 在配置了支持广播的接口上,与IFA_LOCAL一样,同样表示本地ip地址: 2. 对于点对点链路,IFA_ADDRESS表示的是对端的地 ...
- 原始套接字&&数据链路层访问
1. 原始套接字能力: (1) 进程可以读写ICMP,IGMP等分组,如ping程序: (2) 进程可以读写内核不处理协议字段的ipv4数据报:如OSPF等: (3) 进程可以使用IP_HDRINCL ...
- bzoj 1015 星球大战starwar
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1015 题解: 如果按照题目的意思,每次删点.删边太困难了……于是采用逆向思维,构造出最后的 ...
- 自动安装jar包到本地仓库
参考博客:http://blog.csdn.net/m0_37797991/article/details/73394873
- windows系统安装mysql压缩zip版
1.下载 打开官网:https://www.mysql.com 进入DOWNLOADS--->Community--->MySQL Community Server,选择系统对应的版本点击 ...