HDU-5234 Happy Birthday

Source: Internet
Author: User

problem DescriptionToday is Gorwin ' s birthday. So she mother want to realize her a wish. Gorwin says that she wants to eat many cakes. Thus, her mother takes she to a cake garden.

The garden was splited into n*m grids. In each grids, there is a cake. The weight of cake in the i-th row j-th column isWiJ Kilos, Gorwin starts from the Top-left (all) grid of the garden and walk to the Bottom-right (n,m) grid. In each step Gorwin can go to right or down, i.e when Gorwin stands in (i,j), then she can go to (i+1,j) or (i,j+1) (Howev Er, she can not be go out of the garden).

When Gorwin reachs a grid, she can eat up the cake in that grid or just leave it alone. However she can ' t eat part of the cake. But Gorwin's belly is not very large, so she can eat at the most K kilos cake. Now, Gorwin have stood in the Top-left grid and look at the "Map of the garden" she want to find a route which can leads her To eat most cake. But the map was so complicated. So she's wants you.  InputMultiple test cases, every case gives N, M, K

In the next n lines, the i-th line contains m integersWI1,WI2 , wi3< Span id= "mathjax-span-43" class= "Mo" >,? w i m Which describes the weight of cakes in the i-th row

Please process to the end of file.

[Technical specification]

All inputs is integers.

1<=n,m,k<=100

1<=WiJ<=100
  Outputfor each case, output a integer in a single line indicates the maximum weight of cake gorwin can eat.
Sample Input1 1 232 3  -1 2 34 5 6Sample Output0 -Hintin the first Case, Gorwin can ' t eat part of cake, so she can ' t eat any cake. in the second Case, Gorwin walks though below route (1,1), (2,1), (2,2), (2,3). When she passes a grid, she eats up the cakeinchThat grid. Thus The total amount cake she eats is 1+4+5+6= -.

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5234

************************************************

Test instructions

Analysis:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cmath>6#include <stack>7#include <map>8#include <vector>9 using namespacestd;Ten  One #defineN 110 A #defineINF 0x3f3f3f3f -  - intmaps[ $][ $],dp[n][n][n]; the  - intMain () - { -     intn,i,j,m,kk,k,x,y; +  -      while(SCANF (" %d%d%d", &AMP;N,&AMP;M,&AMP;KK)! =EOF) +     { AMemset (DP,0,sizeof(DP)); atmemset (Maps,0,sizeof(maps)); -  -          for(i=1; i<=n; i++) -              for(j=1; j<=m; J + +) -scanf"%d", &maps[i][j]); -  in          for(i=1; i<=n; i++) -              for(j=1; j<=m; J + +) to                  for(k=0; k<=kk; k++) +                 { -                    if(k<Maps[i][j]) theDp[i][j][k]=max (dp[i-1][j][k], dp[i][j-1][k]); *                    Else $                    {Panax NotoginsengX=max (dp[i-1][J][K-MAPS[I][J]], dp[i][j-1][K-MAPS[I][J]]) +Maps[i][j]; -Y=max (dp[i-1][j][k], dp[i][j-1][k]); thedp[i][j][k]=Max (x, y); +                    } A                 } the  +printf"%d\n", Dp[n][m][kk]); -     } $     return 0; $ } - ///General also really do not think three-dimensional,%>_<%, a think on the original is not so complex,, hehe da

HDU-5234 Happy Birthday

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.