【动态规划】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 ...
随机推荐
- Angular2.0 基础: Form
对于Angular2.0 的Form表单中的隐藏和验证,个人觉得还是挺有意思的. 1.通过ngModel 跟踪修改状态与验证. 在表单中使用 ngModel 可以获得更多的控制权,包括一些常用的验证. ...
- Python标准库笔记(2) — re模块
re模块提供了一系列功能强大的正则表达式(regular expression)工具,它们允许你快速检查给定字符串是否与给定的模式匹配(match函数), 或者包含这个模式(search函数).正则表 ...
- Linux 入门记录:十、Linux 下获取帮助
一.获取帮助 Linux 提供了极为详细的帮助工具和文档,通过查阅相关文档,可以大大减少需要记忆的东西并提高效率. 二.--help参数 几乎所有命令都可以使用 -h 或 --help 参数获取命令的 ...
- iptables 操作
iptables --list 查看列表 iptables删除规则 iptables -nL --line-number Chain INPUT (policy ACCEPT)num target p ...
- atom编辑器插件atom-ternjs
这是官方文档:https://atom.io/packages/atom-ternjs 官方介绍: JavaScript code intelligence for atom with Tern. A ...
- C# 笔记——索引器
索引器允许类或者结构的实例按照与数组相同的方式进行索引取值,索引器与属性类似,不同的是索引器的访问是带参的. 索引器和数组比较: (1)索引器的索引值(Index)类型不受限制 (2)索引器允许重载 ...
- HIbernate学习笔记2 之 主键生成方式
一.hibernate主键生成方式: 1.常用方式:mysql:自增长生成主键(identity) <generator class="identity"> </ ...
- 3:django models Making queries 高级进阶--聚合运算
在前一遍文章django models Making queries里面我们提到了django常用的一些检索数据库的内容, 下面我们来看一下更为高级的检索聚合运算 这是我们要用到的模型 class A ...
- 七:zooKeeper开源客户端ZkClient的api测试
ZkClient是Gitthub上一个开源的ZooKeeper客户端.ZKClient在ZooKeeper原生API接口之上进行了包装,是一个更加易用的ZooKeeper客户端.同时ZKClient在 ...
- 微信小程序 - 仿南湖微科普小程序游戏环节
最近看到南湖微科普小程序游戏环节感觉还可以,于是模仿了下 <view class='current' animation="{{animation}}"> {{curr ...