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. Ubuntu命令方式安装中文语言包

    Ubuntu命令方式安装中文语言包 安装之前执行 $LANG 查看语言环境 中文语言包: language-pack-zh-hans 简体中文 language-pack-zh-hans-base l ...

  2. Vue点击当前元素添加class 去掉兄弟的class

    <div id="app"> <ul> <li v-for="(todo, index) in todos" v-on:click ...

  3. jenkins 脱机下 安装插件失败

    1.首次进入,提示离线 2.网上给出了绝大部分答案是进入Manage Plugins 中在高级下将升级站点的https换成http,但是都没解决我的问题  还是报错,用了大部分时间查阅 最终才发现问题 ...

  4. 用人话告诉小白:什么是项目管理(例如Maven),什么是调试工具(即debugger),什么是编译(即compile)

    项目管理 以java程序的项目管理软件Maven为例,java程序根据代码的不同需要不同的jar文件才能编译运行. 人物:两个程序员A和B 物品:一个java程序G,许多jar文件 场景:当A在自己电 ...

  5. Java调用ARM模板执行Azure Rest建立VM过程

    Azure Resource Manager 提供一致的管理层,用于管理通过 Azure PowerShell.Azure CLI.Azure 门户.REST API 和开发工具执行的任务,所有工具使 ...

  6. 【前端】HTML总结

    一. HTML介绍:---------------------------------------1. 什么是HTML?   超文本标记语言,  <标签名>--标记(标签.节点)   2. ...

  7. 搭建react项目(低配版)

    react项目低配版,可作为react相关测试的基础环境,方便快速进行测试. git clone git@github.com:whosMeya/simple-react-app.git git ch ...

  8. SQL基础系列(1)-基本语法--转载w3school

    1.    建原始表 USE [Northwind] GO /****** Object:  Table [dbo].[Persons]    Script Date: 2016/6/8 7:31:5 ...

  9. tf.nn.depthwise_conv2d 卷积

    tf.nn.depthwise_conv2d( input, filter, strides, padding, rate=None, name=None, data_format=None ) 参数 ...

  10. AJ学IOS 之微博项目实战(6)导航控制器NavigationController 的滑动回退功能实现

    AJ分享,必须精品 一:效果 第二篇里面写了怎样自定义navigation实现自定义的导航控制器左右按钮样式,但是当我们自己实现后,系统自带的向右边滑动来实现回退的功能就不能用了. 这里主要实现滑动回 ...