Filthy Rich

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4393    Accepted Submission(s): 1898

Problem Description
They say that in Phrygia, the streets are paved with gold. You’re currently on vacation in Phrygia, and to your astonishment you discover that this is to be taken literally: small heaps of gold are distributed throughout the city. On a certain day, the Phrygians even allow all the tourists to collect as much gold as they can in a limited rectangular area. As it happens, this day is tomorrow, and you decide to become filthy rich on this day. All the other tourists decided the same however, so it’s going to get crowded. Thus, you only have one chance to cross the field. What is the best way to do so?

Given a rectangular map and amounts of gold on every field, determine the maximum amount of gold you can collect when starting in the upper left corner of the map and moving to the adjacent field in the east, south, or south-east in each step, until you end up in the lower right corner.

 
Input
The input starts with a line containing a single integer, the number of test cases.
Each test case starts with a line, containing the two integers r and c, separated by a space (1 <= r, c <= 1000). This line is followed by r rows, each containing c many integers, separated by a space. These integers tell you how much gold is on each field. The amount of gold never negative.
The maximum amount of gold will always fit in an int.
 
Output
For each test case, write a line containing “Scenario #i:”, where i is the number of the test case, followed by a line containing the maximum amount of gold you can collect in this test case. Finish each test case with an empty line.
 
Sample Input
1
3 4
1 10 8 8
0 0 1 8
0 27 0 4
 
Sample Output
Scenario #1:
42

一道dp题, 从左上角走到右下角,只能往右、下或右下走,求捡到的金子最多为多少。

#include <iostream>
#include <stdio.h>
#include <string.h> using namespace std; int dp[][]; int Max(int a, int b)
{
return a>b? a:b;
} int main()
{
int t, r, c;
scanf("%d", &t);
for(int i=; i<; i++)
{
dp[i][]=;
dp[][i]=;
}
for(int k=; k<t; k++)
{
scanf("%d%d", &r, &c); for(int i=; i<=r; i++)
for(int j=; j<=c; j++)
{
scanf("%d", &dp[i][j]);
dp[i][j] += Max(dp[i-][j], dp[i][j-]);
}
printf("Scenario #%d:\n", k+);
printf("%d\n\n", dp[r][c]);
} return ;
}

hdu_2391 Filthy Rich DP的更多相关文章

  1. HDU 2391 Filthy Rich (dp)

    题目连接 Problem Description They say that in Phrygia, the streets are paved with gold. You're currently ...

  2. hdu 2391 Filthy Rich

    单纯dp 水一 处理时间点,第一行和第一列特殊处理: 其余的w[i][j]=show(w[i-1][j-1],w[i-1][j],w[i][j-1]); <span style="fo ...

  3. (转) [it-ebooks]电子书列表

    [it-ebooks]电子书列表   [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...

  4. JAVA 画图机制

    java学习脚印:深入java绘图机制 写在前面 封装性越好的类在使用时,只要清楚接口即可,而不应该让程序员了解其内部结构; 对于平常的绘图来讲,java绘图机制无需了解太多,但是朦胧容易产生错误,绘 ...

  5. ACM: 强化训练-Beautiful People-最长递增子序列变形-DP

    199. Beautiful People time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard ...

  6. hdu--(1025)Constructing Roads In JGShining's Kingdom(dp/LIS+二分)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  7. 你有PSD的学位吗? - dp的日志 - 网易博客

    你有PSD的学位吗? - dp的日志 - 网易博客 你有PSD的学位吗? 2011-08-01 12:58:40|  分类: 感悟 |  标签:自我提升   |字号 大中小 订阅       去年, ...

  8. (中等) POJ 2948 Martian Mining,DP。

    Description The NASA Space Center, Houston, is less than 200 miles from San Antonio, Texas (the site ...

  9. Humble Numbers HDU - 1058 2分dp

    JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two ...

随机推荐

  1. Kafka监控:主要性能指标

    Kafka是什么? Kafka是一个分布式,有分区的,有副本的日志服务系统,由LinkedIn公司开发,并于2011年开源.从本质上来说,Kafka拥有一套可扩展的发布/订阅消息队列架构,并组成了一套 ...

  2. 艾编程coding老师课堂笔记:SpringBoot源码深度解析

    思想:有道无术,术尚可求,有术无道,止于术! Spring 开源框架,解决企业级开发的复杂性的问题,简化开发 AOP, IOC Spring 配置越来多,配置不方便管理! Javaweb---Serv ...

  3. Win32程序:与"LPCWSTR"类型的形参不兼容

    出现该问题的原因是通常手动输入的字符串都是LPCSTR类型的, 解决办法如下: 在工程处右键,属性-常规-字符集,将Unicode字符集改为为多字节字符集,应用并确认即可.   字符串常量报错: 在常 ...

  4. Vue-router 第10节 路由中的钩子

    Vue-router 第10节 路由中的钩子 [TOC] 第10节 路由中的钩子 我们知道一个组件从进入到销毁有很多的钩子函数,同样在路由中也设置了钩子函数.路由的钩子选项可以写在路由配置文件中,也可 ...

  5. 教你爬取腾讯课堂、网易云课堂、mooc等所有课程信息

    本文的所有代码都在GitHub上托管,想要代码的同学请点击这里

  6. AJ学IOS(45)之常用的小功能比如打电话、打开网址、发邮件、发短信打开其他应用。

    AJ分享,必须精品 简介 iOS中的很多小功能都是非常简单的,几行代码就搞定了,比如打电话.打开网址.发邮件.发短信.打开其他应用等. 打电话 方法1 最简单最直接的方式:直接跳到拨号界面 NSURL ...

  7. Keepalived实现Nginx负载均衡高可用

    第一章:keepalived介绍 VRRP协议 目的就是为了解决静态路由单点故障问题的 第二章: keepalived工作原理 2.1 作为系统网络服务的高可用功能(failover) keepali ...

  8. 08-less预处理器

    一.less预处理器 Less(LeanerStyle Sheets 的缩写)是一门 CSS扩展语言,也成为CSS预处理器. 1.插件安装 安装Easy LESS插件就能使写入的.less文件保存时自 ...

  9. 【Java】标识符 & 命名规则

    Java的标识符和命名规则 什么是标识符[Identifier]? 指用来标识某个实体的一个符号.在不同的应用环境下有不同的含义. 在编程语言中,标识符是开发者编程时使用的名字,对于变量.常量.函数. ...

  10. 【LeetCode】23.合并K个排序链表

    题目描述 23.合并K个排序链表 合并k个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例: 输入: [ 1->4->5, 1->3->4, 2->6 ] ...