Codeforces Gym 100500H A. Potion of Immortality Simple DP

Source: Internet
Author: User

Problem H. ICPC Quest
Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

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, Dr. Mohamed Fo ' AD, the ACPC regional Contest Director, asked Noura to play One of the ICPC Quests. ICPC Quests is a set of challenges that might require the contestants-move around the city searching for some monument s, solving puzzles, or getting a high score in a certain game. The rules of the quests states that the contestants would post the answer to the quest to Twitter using these hashtags #ICP C2014 #QuestN where N is the quest number. The contestant would post a photo or a short video (a Vine) of the challenge he accomplished. The scores of the challenges is accumulated and the one with the highest score would get an Android tablet. Noura is so EnthuSiastic about the Quest number 14. Quest was on a grid of n rows and M columns, and each cell of the grid contains an integer, and whenever a Contestan T steps on a cell he's going to add it value to his total accumulated sum. The task was-to-start from the top left cell located at (all) and to moves only right or under order to get to cell (n,m) , and during this journey the contestant have to get the maximum sum possible. The player who can get the maximum possible score are announced as the winner of this quest. You'll be given the description of the grid, please help Noura determining the maximum possible score she can get.

Input

The first line would be the number of test cases T. Each test case starts with 2 integers n, m where n was the number of rows while M is the number of columns. They'll be followed by n rows each containing m numbers, and the absolute value of the number in each cell would not exce Ed 100. 1 <= T <= 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 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

Test instructions

You can go down, you can go to the right, and then ask you to walk from the n,m to the past, and the maximum can be how much

The following:

Simple DP, direct two-dimensional walk just fine

Code

#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>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)Const intmaxn=202501;#defineMoD 1000000007#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//*************************************************************************************ll dp[1011][1011];ll a[1011][1011];intMain () {intt=read ();  for(intcas=1; cas<=t;cas++)    {        intN=read (), m=read ();  for(intI=1; i<=n;i++)        {             for(intj=1; j<=m;j++) {A[i][j]=read (); }        }         for(intI=1; i<=n;i++)        {             for(intj=1; j<=m;j++)            {                if(i==1) Dp[i-1][j]=-inf; if(j==1) Dp[i][j-1]=-inf; if(i==1&&j==1) Dp[i-1][j]=0; DP[I][J]=max (dp[i-1][j],dp[i][j-1])+A[i][j]; }} printf ("Case %d:%lld\n", Cas,dp[n][m]); }}

Codeforces Gym 100500H A. Potion of Immortality Simple DP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.