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. 1021 Deepest Root (25 分)

    A graph which is connected and acyclic can be considered a tree. The height of the tree depends on t ...

  2. Linux下修改efi启动项

    Linux下有一个efibootmgr工具可以编辑efi启动项,十分方便,简单介绍如下 直接运行efibootmgr会显示出当前所有efi启动项,每个启动项前都有相应编号, 可以使用efibootmg ...

  3. Linq下有一个非常实用的SelectMany方法,很多人却不会用

    在平时开发中经常会看到有些朋友或者同事在写代码时会充斥着各种for,foreach,这种程式代码太多的话阅读性特别差,而且还显得特别累赘,其实在FCL中有很多帮助我们提高阅读感的方法,而现实中很多人不 ...

  4. 【django基础】django接口 异步ajax请求 导出数据库成excel表(包裹前端后端)

    py文件: from django.utils.http import urlquote from rest_framework.views import APIView from django.sh ...

  5. 28.5 Integer-- int的包装类

    * 由于基本数据类型只能做一些简单的操作和运算,所以Java为我们封装了基本数据类型,为每种基本数据类型提供了包装类 * 包装类就是封装了基本数据类型的类,为我们提供了更多复杂的方法和一些变量 * * ...

  6. 23 抽象类 abstract

    /*概念 * abstract:关键字,用于修饰方法和类 * 抽象方法:不同类的方法是相似,但是具体内容又不太一样,所以我们只能抽取他的声明,没有具体的方法体,没有具体方法体的方法就是抽象方法 * 抽 ...

  7. java京东自动登录

    大部分代码都是参考的这边,我只是在他的逻辑上实现了自动通过验证码,放上主逻辑的代码吧,图片识别我用的若快,可以去接其他平台 https://blog.csdn.net/u013232789/artic ...

  8. 很用心的为你写了 9 道 MySQL 面试题

    MySQL 一直是本人很薄弱的部分,后面会多输出 MySQL 的文章贡献给大家,毕竟 MySQL 涉及到数据存储.锁.磁盘寻道.分页等操作系统概念,而且互联网对 MySQL 的注重程度是不言而喻的,后 ...

  9. windows 环境下dos 命令符下进D盘(非c盘系统盘)根目录

    怎么进? 先 cd  D: 然后 直接  D: 即可到D盘根目录,至于为啥要输入2遍D 才进D盘根目录,这就是windows的规定

  10. CentOS7安装JAVA环境

    安装JAVA环境我常用的有两种形式 1.下载tar包安装 2.下载rpm包直接安装 本篇内容就写这两种形式的安装方法: JAVA程序的下载地址:https://www.oracle.com/java/ ...