zoukankan      html  css  js  c++  java
  • hdu 5234

    题意:求在不超过k的情况下,最多可以得到多少价值。

    三维dp,结合01背包,第三维就是用来保存在不同的背包容量下能得到的最大价值,也就是第三维有很多状态。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<cctype>
    #include<queue>
    #include<stack>
    #include<vector>
    #include<algorithm>
    
    using namespace std;
    typedef long long LL;
    #define N 110
    #define INF 0x3f3f3f3f
    
    int n, m, k;
    int a[N][N], dp[N][N][N];
    
    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]);
    
            memset(dp, 0, sizeof(dp));
    
            for(int i=1; i<=n; i++)
            {
                for(int j=1; j<=m; j++)
                {
                   for(int l=k; l>=a[i][j]; l--)
                   { 
                       int x=max(dp[i][j-1][l], dp[i-1][j][l]);
                       int y=max(dp[i][j-1][l-a[i][j]]+a[i][j], dp[i-1][j][l-a[i][j]]+a[i][j]);
                       dp[i][j][l]=max(x, y);
                   } 
                }
            }
            printf("%d
    ", dp[n][m][k]);
        }
        return 0;
    }
  • 相关阅读:
    网络规划和布线
    网络编程
    NoSQL 非关系数据库
    OpenCV
    首页
    C++关键字
    TCP/IP 详解7 Ping指令
    TCP详解 (1)
    GRE封装解封装过程
    GRE tunnel
  • 原文地址:https://www.cnblogs.com/9968jie/p/5799364.html
Copyright © 2011-2022 走看看