Problem H. ICPC Quest
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100500/attachments

Description

Noura Boubou is a Syrian volunteer at ACM ACPC (Arab Collegiate Programming Contest) since 2011. She graduated from Tishreen University where she studied Information Technology. She is the head of the photography team responsible for photo-shooting the Arabs joining the world finals. On the first day of the world finals last year, Dr Mohamed Fo’ad, the ACPC Regional Contest Director, asked Noura to play one of the ICPC Quests. ICPC Quests are a set of challenges that might require the contestants to move around the city searching for some monuments, solving puzzles, or getting a high score in a certain game. The rules of the quests states that the contestants will post the answer to the quest to Twitter using these hashtags #ICPC2014 #QuestN where N is the quest number. The contestant will post a photo or a short video (a Vine) of the challenge he accomplished. The scores of the challenges are accumulated and the one with the highest score will get an Android tablet. Noura was so enthusiastic about the Quest number 14. Quest 14 was about a grid of n rows and m columns, and each cell of the grid contains an integer, and whenever a contestant steps on a cell he is going to add its value to his total accumulated sum. The task was to start from the top left cell located at (1,1) and to move only right or down in order to get to cell (n,m), and during this journey the contestant has to get the maximum sum possible. The player who can get the maximum possible score is announced as the winner of this quest. You will be given the description of the grid, please help Noura determining the maximum possible score she can get.

Input

The first line will be the number of test cases T. Each test case starts with 2 integers n, m where n is the number of rows while m is the number of columns. They will be followed by n rows each containing m numbers, and the absolute value of the number in each cell will not exceed 100. 1 <= T <= 100 1 <= n,m <= 1000 -100 <= celli,j <= 100

Output

For each test case print a single line containing: Case_x:_y x is the case number starting from 1. y is is the required answer. Replace underscores with spaces.

Sample Input

2 3 3 1 2 3 -1 -2 -3 1 1 1 2 3 1 1 2 2 1 5

Sample Output

Case 1: 4 Case 2: 9

HINT

题意

你可以往下走,也可以往右走,然后问你从1,1走到n,m,求路过的和最大可以为多少

题解

简单dp,直接二维走就好了

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
const int maxn=;
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* ll dp[][];
ll a[][];
int main()
{
int t=read();
for(int cas=;cas<=t;cas++)
{
int n=read(),m=read();
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
a[i][j]=read();
}
}
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(i==)
dp[i-][j]=-inf;
if(j==)
dp[i][j-]=-inf;
if(i==&&j==)
dp[i-][j]=;
dp[i][j]=max(dp[i-][j],dp[i][j-])+a[i][j];
}
}
printf("Case %d: %lld\n",cas,dp[n][m]);
}
}

codeforces Gym 100500H A. Potion of Immortality 简单DP的更多相关文章

  1. codeforces Gym 100187A A. Potion of Immortality

    A. Potion of Immortality Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1001 ...

  2. codeforces gym #101161H - Witcher Potion(状压DP)

    题目链接: http://codeforces.com/gym/101161/attachments 题意: 总共有n瓶药可供选择 每瓶药可以增加$e_i$点体力,和$p_i$点毒性 每分钟消耗1点毒 ...

  3. Codeforces Round #260 (Div. 1) A. Boredom (简单dp)

    题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...

  4. codeforces Gym 100500H H. ICPC Quest 水题

    Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...

  5. Gym - 100187A A - Potion of Immortality —— 贪心

    题目链接:http://codeforces.com/gym/100187/problem/A 题解: 光题意就想了很久:在最坏情况下的最小兔子数.其实就是至少用几只兔子就一定能找出仙药(答案存在的话 ...

  6. Codeforces Gym 100015F Fighting for Triangles 状压DP

    Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph ...

  7. Codeforces GYM 100114 D. Selection 线段树维护DP

    D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descriptio ...

  8. codeforces 687C - The Values You Can Make 简单dp

    题意:一个数组a[i],你可以挑出若干个数(只能挑一次)加起来等于k, 针对每一种方案,你可以选出这若干个数的子集来组合新数 最后所有的方案能组合出多少种数 分析:一看数据范围n,k<=500 ...

  9. Codeforces Gym 100286F Problem F. Fibonacci System 数位DP

    Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

随机推荐

  1. android学习笔记六

    Android中Activity的Intent大全 Api Level 3: (SDK 1.5) android.intent.action.ALL_APPS android.intent.actio ...

  2. 编译boost (windows msvc14)

    我的环境 OS: WIN10 (x64) IDE: VS2015 (VC14) http://www.boost.org/ 1. 下载 下载boost包, boost_1_62_0.7z 使用ASIO ...

  3. HDU 5433 Xiao Ming climbing

    题意:给一张地图,给出起点和终点,每移动一步消耗体力abs(h1 - h2) / k的体力,k为当前斗志,然后消耗1斗志,要求到终点时斗志大于0,最少消耗多少体力. 解法:bfs.可以直接bfs,用d ...

  4. Python--类使用

    类使用的几个注意点: 1. 类的语法结构:2. __init__(self),3. __metaclass__=type, (新式类)4. super(subclassname, self).__in ...

  5. C++ 出现bug :二位数组的操作运算,求非对角线的元素的和

    编写一个通用程序,求出二位数组(行数和列数必须相等)的非对角线的元素之和,试建立类MATRIX完成上述功能 #include<iostream> using namespace std; ...

  6. res/raw和assets的 区别

    res/raw和assets的相同点: 两者目录下的文件在打包后会原封不动的保存在apk包中,不会被编译成二进制. res/raw和assets的不同点: 1.res/raw中的文件会被映射到R.ja ...

  7. 线性模型(3):Logistic Regression

    此笔记源于台湾大学林轩田老师<机器学习基石><机器学习技法> (一)Logistic Regression 原理 对于分类问题,假设我们想得到的结果不是(x属于某一类)这种形式 ...

  8. Tkinter教程之Listbox篇

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811310 #Tkinter教程之Listbox篇#Listbox为列表框控件,它可以包含一个 ...

  9. 《Genesis-3D开源游戏引擎完整实例教程-2D射击游戏篇08:弹幕系统》本系列完结

    8.弹幕系统 弹幕系统概述: 弹幕系统的设计体现了射击游戏的基本要素,玩家要在敌人放出的大量子弹(弹幕)的细小空隙间闪避,能在玩家闪躲弹幕的时候给玩家带来快感,接近满屏的子弹,增加了对玩家的视觉冲击力 ...

  10. JAVA WEB SQLHelper类的封装

    在这次做项目中,我对自己最满意的就是封装了一下SQLHelper类,我对自己感到骄傲主要是 我是初学者,我刚开始不知道可以这样做,我只是想着试着去这样做了,结果真的可以,所以我 在我的模块就自己封装了 ...