• HDU 5501 背包问题


    需要按照B/C的值从大到小排序。

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<cmath>
    #include<queue>
    #include<vector>
    #include<map>
    using namespace std;
    typedef long long LL;
    const int INF = 1e9+7;
    const int maxn = 1015;
    const int MOD = 9973;
    
    int A[maxn], B[maxn], C[maxn];
    int dp[3005];
    int vis[maxn];
    
    struct node
    {
        int A, B, C;
        bool friend operator < (node a, node b)
        {
            return 1.0*a.B/a.C > 1.0*b.B/b.C;
        }
    }P[maxn];
    
    
    int main()
    {
        int T;
        scanf("%d",  &T);
    
        while(T--)
        {
            int n, t;
            scanf("%d %d", &n, &t);
            for(int i=1; i<=n; i++)
                scanf("%d %d %d", &P[i].A, &P[i].B, &P[i].C);
    
            sort(P+1, P+n+1);
            memset(dp, 0, sizeof(dp));
    
            for(int i=1; i<= n; i++)
                vis[i] = INF;
    
            for(int i=1; i<=n; i++)
            {
                for(int j=t; j>=P[i].C; j--)
                    dp[j] = max(dp[j], dp[j-P[i].C] + P[i].A - P[i].B*j);
            }
    
            int ans = 0;
            for(int i=0; i<= t; i++)
                ans = max(ans, dp[i]);
    
            printf("%d
    ", ans);
        }
        return 0;
    }
    /*
    1
    2 10
    110 5 9
    30 2 1
    */
  • 相关阅读:
    SpringBoot构建RESTful API
    Zynq7000系列之芯片系统结构概述
    FPGA编程技巧系列之按键边沿检测
    异常处理规范
    接口定义规范
    工具类编写规范
    第三个月
    测试计算器心得
    2015年三月
    第一份工作
  • 原文地址:https://www.cnblogs.com/chenchengxun/p/4871912.html
Copyright © 2020-2023  润新知