zoukankan      html  css  js  c++  java
  • HDU

    Problem Description
    Today is Gorwin’s birthday. So her mother want to realize her a wish. Gorwin says that she wants to eat many cakes. Thus, her mother takes her to a cake garden. 

    The garden is splited into n*m grids. In each grids, there is a cake. The weight of cake in the i-th row j-th column is wij kilos, Gorwin starts from the top-left(1,1) 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) (However, she can not 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 most K kilos cake. Now, Gorwin has stood in the top-left grid and look at the map of the garden, she want to find a route which can lead her to eat most cake. But the map is so complicated. So she wants you to help her.
     
    Input
    Multiple test cases (about 15), every case gives n, m, K in a single line.

    In the next n lines, the i-th line contains m integers wi1,wi2,wi3,wim which describes the weight of cakes in the i-th row

    Please process to the end of file.

    [Technical Specification]

    All inputs are integers.

    1<=n,m,K<=100

    1<=wij<=100
     
    Output
    For each case, output an integer in an single line indicates the maximum weight of cake Gorwin can eat.
    Sample Input
    1 1 2
    3
    2 3 100
    1 2 3
    4 5 6
     
    
    Sample Output
    0
    16
    
    Hint
    In 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 cake in that grid. Thus the total amount cake she eats is 1+4+5+6=16.

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5234

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

    题意:

    分析:

     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 namespace std;
    10 
    11 #define N 110
    12 #define INF 0x3f3f3f3f
    13 
    14 int maps[200][200],dp[N][N][N];
    15 
    16 int main()
    17 {
    18     int n,i,j,m,kk,k,x,y;
    19 
    20     while(scanf("%d %d %d", &n,&m,&kk) != EOF)
    21     {
    22         memset(dp,0,sizeof(dp));
    23         memset(maps,0,sizeof(maps));
    24 
    25         for(i=1; i<=n; i++)
    26             for(j=1; j<=m; j++)
    27                 scanf("%d", &maps[i][j]);
    28 
    29         for(i=1; i<=n; i++)
    30             for(j=1; j<=m; j++)
    31                 for(k=0; k<=kk; k++)
    32                 {
    33                    if(k<maps[i][j])
    34                     dp[i][j][k]=max(dp[i-1][j][k], dp[i][j-1][k]);
    35                    else
    36                    {
    37                         x=max(dp[i-1][j][k-maps[i][j]], dp[i][j-1][k-maps[i][j]])+maps[i][j];
    38                         y=max(dp[i-1][j][k], dp[i][j-1][k]);
    39                        dp[i][j][k]=max(x, y);
    40                    }
    41                 }
    42 
    43         printf("%d
    ", dp[n][m][kk]);
    44     }
    45     return 0;
    46 }
    47 ///一般还真不咋想三维,%>_<%,一想就发现原来没那么复杂了,,呵呵哒
  • 相关阅读:
    2028 ACM Lowest Common Multiple Plus
    2032 杨辉三角
    2011 ACM 0和1思想
    grid
    Change position in observation
    1490 ACM 数学
    1489 ACM 贪心
    2009 ACM 水题
    Book Lending Registration
    MR1和MR2(Yarn)工作原理流程
  • 原文地址:https://www.cnblogs.com/weiyuan/p/5777153.html
Copyright © 2011-2022 走看看