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 版本自动更新

    截图如下: 代码实现如下: package com.update.apk; import java.io.BufferedReader; import java.io.File; import jav ...

  2. WPF MultiBinding 和 IMultiValueConverter

    MultiBinding,描述附加到单个绑定目标属性的Binding对象的集合.可以指定多个数值绑定. IMultiValueConverter通过转换器使用MultiBingding对象,该对象讲根 ...

  3. DbContext运行时动态附加上一个dbset

    参考 Creating DbSet Properties Dynamically C# code? 1 DbSet<MyEntity> set = context.Set<MyEnt ...

  4. cannot conform to protocol 的一点事

    学习UITableView过程中,回想视频打一遍代码,发现卡在了第一步.一直显示无法继承协议,而且还多了一个错误:definition conflicts with previous value.百度 ...

  5. Trail: JDBC(TM) Database Access(3)

    java.sql,javax.sql,javax.naming包    默认TYPE_FORWARD_ONLY:结果集只能向前滚动,只能调用next(),不能重定位游标 TYPE_SCROLL_INS ...

  6. 让sublime text 2更好地支持Python

    SublimeCodeIntel: ~/.codeintel/config里加了python和pythonExtraPaths的路径(Mac): {"Python" : {&quo ...

  7. cocos2d-x生成随机数

            //获取系统时间         //time_t是long类型,精确到秒,通过time()函数可以获得当前时间和1970年1月1日零点时间的差         time_t tt; ...

  8. work_6

    这次的作业是阅读C++11的新特性并提出问题,作为一个大部分代码都是用C++的基本语法并没有特别关注C++一代又一代新特性的学生来说,首先我阅读了一些关于新特性的文章.为了更快的理解,我首先选择了阅读 ...

  9. 关于scrollTop的那些事

    大家在实际项目中,应该是要经常用到scrollTop的,它表示的是可视窗口距离页面顶部的距离,这个scrollTop是可读写的,所以可以用来做页面滚动. 但是大家或多或少遇到一些浏览器兼容问题,为什么 ...

  10. 发布ASP.NET网站时的设置

    在ASP.NET网站开发完成之后,一般都要进行发布,然后再使用. 点击“目标位置”后的按钮可以选择将网站发布到的位置,有“本地.本机IIS.FTP站点.远程网站站点”四个选项. 另外,发布网站时还有四 ...