Bestcoders Happy Birthday

Source: Internet
Author: User

Happy Birthdayaccepts:178submissions:511Time limit:2000/1000 MS (java/others)Memory limit:65536/65536 K (java/others) Problem description
Today is Gorwin's birthday. So her mother is going to fulfill one of her wishes. Gorwin said she wanted to eat a lot of cakes. So his mother took her to the cake garden. The garden was divided into n*m squares. In every lattice, there is a cake. Row i, column J of the lattice has a weight of
   
     
     w     i  j                
        
    
   Kilograms of cake, gorwin from the upper left corner of the lattice to walk, go to the lower right corner (n,m) lattice. In each step, Gorwin can go right or down, that is: Gorwin (i,j), she can walk to (i+1,j) or (i,j+1) (but she cannot walk out of the garden). When Gorwin arrives at a lattice, she can eat or not eat the cake in that lattice. But she can't just eat part of it. Her stomach is not so big, so she can only eat a K-kilogram cake. Now, Gorwin is standing in the upper left corner, looking at the map of the cake garden and trying to find a way to make the most of the cake she eats. Please come and help me.
Enter a description
Multiple sets of test data (approximately 15 groups), each set of data given in a row n, M, K. In the next n rows, the line I has a M integer
   
      w  i1  ,  w  i2  ,  w  i3  ,?  w  im  
   , representing the weight of the M-Cake on line I. Please process to the end of the file. [Parameter Convention] all inputs are integers. 1<=n,m,k<=1001<=
   
    
         wiJ     
 

    
   <=100
Output description
For each data, output a value that represents the maximum cake weight that gorwin can eat.
Input sample
1 1 232 3 1001 2 34 5 6
Output sample
016
Hint
In the first set of data, Gorwin can't eat part of the cake, so she can't eat any cakes. In the second data, Gorwin follows the path (2,1), (2,2), (2,3)

When she passed a lattice, she ate up the cake in that lattice. So the total weight she eats is 1+4+5+6=16.

#include <bits/stdc++.h>using namespace std; #define MAXN + 5int a[maxn][maxn];int d[maxn][maxn][maxn];int N, M, K;void solve () {    memset (d, 0, sizeof (d));    for (int i=1, i<=n; i++) for        (int j=1; j<=m; j + +) for           (int t=0; t<=k; t++)    {        if (T < a[i][j]) 
    
     d[i][j][k] = max (d[i-1][j][t], d[i][j-1][t]);        else d[i][j][t] = max (max (d[i-1][j][t], d[i][j-1][t]), Max (D[i-1][j][t-a[i][j]]+a[i][j], d[i][j-1][t-a[i][j]]+a[i][j ]));    }    int ans = 0;    for (int i=1; i<=k; i++)        ans = max (ans, d[n][m][i]);    printf ("%d\n", ans);} int main () {while    (~scanf ("%d%d%d", &n, &m, &k))    {for        (int. i=1; i<=n; i++) for            (Int J = 1; j<=m; J + +)            scanf ("%d", &a[i][j]);        Solve ();    }    return 0;}
    


Bestcoders Happy Birthday

Related Article

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.