【动态规划】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 ...
随机推荐
- html+js+node实现五子棋线上对战,五子棋最简易算法
首先附上我的github地址,https://github.com/jiangzhenfei/five,线上实例:http://47.93.103.19:5900/client/ 线上实例,你可以随意 ...
- Jquery checkbox 遍历
checkbox 全选\全部取消 $("#ChkAll").click(function(){ $("#divContent input[type='checkbo ...
- Java 中的方法内部类
方法内部类就是内部类定义在外部类的方法中,方法内部类只在该方法的内部可见,即只在该方法内可以使用. 一定要注意哦:由于方法内部类不能在外部类的方法以外的地方使用,因此方法内部类不能使用访问控制符和 s ...
- 时间盲注脚本.py
时间盲注脚本 #!/usr/bin/env python # -*- coding: utf-8 -*- import requests import time payloads = 'abcdefg ...
- defconfig file 的 位置
Platform MSM8917 MSM8937 defconfig file position Android/kernel/msm-3.18/arch/arm/configs/
- 搭建selenium+python自动化环境
1.安装python,下载地址:http://python.org---安装版本3.5.1 ps:自带setuptools和pip工具 2.然后,用pip安装开发Web App需要的第三方库:异步框架 ...
- ubuntu 10.04打开错误
打开ubuntu时,出现的错误如下: Invalid configuration file. File "E:\Ubuntu12.04.vmwarevm\Ubuntu12.04.vmx&qu ...
- C# 笔记——数据类型
一张图读懂C#数据类型:
- ES6 promise简单实现
基本功能实现: function Promise(fn){ //需要一个成功时的回调 var doneCallback; //一个实例的方法,用来注册异步事件 this.then = function ...
- Leetcode 之Longest Common Prefix(33)
在一组字符串中找到最长的子串.采用纵向匹配,遇到第一个不匹配的停止. string longestComPrefix(vector<string> &strs) { if (str ...