方格取数。

但由于题意说金币数<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的更多相关文章

  1. Search gold(dp)

    Search gold Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Subm ...

  2. CDOJ 1271 Search gold

    简单DP.dp[i][j]表示走到这格的最大金钱数. #include<cstdio> #include<cstring> #include<cmath> #inc ...

  3. UESTC--1271--Search gold(贪心)

    Search gold Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu Submit Sta ...

  4. 第七届ACM趣味程序设计竞赛第四场(正式赛) 题解

    Final Pan's prime numbers 题目连接: http://acm.uestc.edu.cn/#/problem/show/1272 题意 给你n,要求你在[4,n]范围内找到一个最 ...

  5. 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 ...

  6. 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 ...

  7. LEETCODE —— Unique Binary Search Trees [动态规划]

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  8. 【POJ3280/洛谷2890】[Usaco2007 Open Gold]Cheapest Palindrome(动态规划)

    题目: POJ3280 洛谷2980 分析: 首先,考虑只可以加字的情况 设\(s[i]\)表示第\(i\)个字符,\(add[i]\)表示加上一个字母\(i\)的花费,\(dp[i][j]\)表示把 ...

  9. [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二

    Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...

随机推荐

  1. select下拉箭头改变,兼容ie8/9

    各个浏览器下select默认的下拉箭头差别较大,通常会清除默认样式,重新设计 <html> <head> <meta charset="utf-8"& ...

  2. node启动服务

    npm install http-server -g http-server ipconfig查看当前ip 手机可访问第一个网址.

  3. Linux汇编教程03:大小比较操作

    我们在上一讲中,简单了解了汇编程序大概的样子.接下来我们来了解一下,汇编程序的大小比较操作.所以我们以编写寻找一堆数中的最大值作为学习的载体. 在编写程序之前,先要分析我们的目的,在得出解决方案. 目 ...

  4. 非 GUI 模式运行 JMeter 压力测试

    非 GUI 模式,即命令行模式,运行 JMeter 测试脚本能够大大缩减所需要的系统资源. 使用命令:jmeter -n -t <testplan filename> -l <lis ...

  5. 排名函数row_number() over(order by)用法

    1. 定义 简单的说row_number()从1开始,为每一条分组记录返回一个数字,这里的ROW_NUMBER() OVER (ORDER BY [列名]DESC) 是先把[列名]降序排列,再为降序以 ...

  6. 虚拟机 VMware Workstation12 安装OS X 系统

      Windows下虚拟机安装Mac OS X —– VMware Workstation12安装Mac OS X 10.11 本文即将介绍WIN虚拟MAC的教程.完整详细教程(包含安装中的一些问题) ...

  7. git命令详情

    1.安装 yum install git 2.创建版本库 git init 3.添加文件 git add file.txt 4.提交文件 git commit -m “新增文件” 5.仓库当前状态 g ...

  8. css设置div等标签背景半透明

    三种方式: 1. background-color: transparent; 直接设置背景为透明 2.这种是子元素也会跟着变成半透明 /* 背景半透明,1为不透明 */ opacity: 0.5; ...

  9. linux命令(38):traceroute命令

    1.命令格式: traceroute[参数][主机] 2.命令功能: traceroute指令让你追踪网络数据包的路由途径,预设数据包大小是40Bytes,用户可另行设置. 具体参数格式:tracer ...

  10. python mock的简单使用

    参考文章: http://blog.csdn.net/wenph2008/article/details/46862771 内容待填充...