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\n", ans);
    }
    return 0;
}
/*
1
2 10
110 5 9
30 2 1
*/
时间: 2024-08-25 05:48:46

HDU 5501 背包问题的相关文章

[2016-02-04][HDU][5501][The Highest Mark]

[2016-02-04][HDU][5501][The Highest Mark] HDU - 5501 The Highest Mark Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %I64d & %I64u Submit Status Description The SDOI in $2045$ is far from what it was been $30$ years ago. Each competition

HDU 1203 背包问题

题目大意: 根据学校的申请费用,根据已有的钱得到最大的offer率 这里很明显就是一个价值为概率的背包问题 计算两个offer合并的概率 为a + b - a*b 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 const int N = 10005; 6 7 double dp[N]; 8 9 int main() 10 { 11 int n

HDU 5501 The Highest Mark (贪心+DP,经典)

题意: 有n道题目,每道题目的初始分数为Ai,分数每分钟减少Bi,完成此题需要Ci分钟,问在t分钟内最多能获得多少分? 思路: 好题~ 如果没有B的话,就是一道裸的01背包的题目了.每道题目的得分为:v=A-B*g  (其中g为完成这道题目的时刻),想要用背包解的话是可以的,但是完成的次序不同的话,得分也可能受到影响.那就排个序得了,问题在于如何排序?假设已经确定要做哪些题了,则如果交换了相邻两道题的位置,对总分数是有益的,那么肯定是换了,而且他们对其他的题目完全无影响,不妨假设只有两道题要完成

hdu 5501 The Highest Mark(贪心+01背包)

题意:类似cf的赛制,每道题目有A,B,C三个值,A表示初始分数,B表示每分钟题的分数会减少B,C表示做这道题需要C分钟,数据保证分数不会变为负数.现在给出比赛时长,问安排做题的顺序,求最大得分. 思路:这道题是一道非常经典的题.首先很容易想到一件事,给出的题哪个先做没有先后顺序,那么在动态规划的时候,必然有前后顺序,所以要么就是状态压缩,要么就是之前就把这些题目排序了,使得后面是有序的.状压不用考虑了因为数据太大,所以我们考虑要如何排序. 现在有A1,B1,C1和A2,B2,C2这两道题,如果

HDU 2602 ——背包问题

Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave … The bone collector had a big bag with a volume of V ,and

第七周 10.12---10.18

新的一周--- >_< gooooooooo---- ---------10.12 hdu 5501 补了周六BC的背包 背包很好想到,一道题目做不做,相当于是01背包,给出t,没有说要不要装满,所以最后扫一遍所有的dp值就可以了 然后就是题目的排序---看的题解了----题解讲得很清楚 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm>

hdu 1114 完全背包问题

题意:给定背包体积与物品的体积与价值 求正好放完的最小价值#include<iostream> using namespace std; int min(int a,int b) { if(a<b) return a; return b; } int main() { int t,m1,m2,n,i,j; int v[502],w[502],dp[10005],m; cin>>t; while(t--) { cin>>m1>>m2; m=m2-m1;

HDU 2602 Bone Collector (01背包问题)

原题代号:HDU 2602 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 原题描述: Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone Collector". This man like to collect varies of bones , such as dog's , cow's ,

hdu 4901 The Romantic Hero (dp+背包问题)

题意: 有n个数,从n个数中选出两个集合s和集合t,保证原序列中,集合s中的元素都在 集合t中元素的左边.且要求集合s中元素做抑或运算的值与集合t中元素做与运算的 值相等.问能选出多少种这样的集合s和t. 算法: 左右dp. 用dp[i][j]表示前i个数 做抑或运算得到j的方法数.最后一个值取不取到都不一定. 故为背包的问题.右边也是一样. 枚举时可能出现重复.枚举到第i个和枚举第i+1个可能重复.所以要枚举一个中间值. 这个中间值是归到s集的,因为抑或支持逆运算,而与是不支持的. 所以最后d