题意:

  有n道题目,每道题目的初始分数为Ai,分数每分钟减少Bi,完成此题需要Ci分钟,问在t分钟内最多能获得多少分?

思路:

  好题~

  如果没有B的话,就是一道裸的01背包的题目了。每道题目的得分为:v=A-B*g  (其中g为完成这道题目的时刻),想要用背包解的话是可以的,但是完成的次序不同的话,得分也可能受到影响。那就排个序得了,问题在于如何排序?假设已经确定要做哪些题了,则如果交换了相邻两道题的位置,对总分数是有益的,那么肯定是换了,而且他们对其他的题目完全无影响,不妨假设只有两道题要完成,现在要决定他们的完成次序。假设先完成题目1,再完成题目2,设t=C1+C2,那么总分为v1=A1-B1*C1 + A2-B2*t;如果交换次序,则总分为v2=A2-B2*C2 + A1-B1*t,那么v1<=v2时,明显有必要交换位置。

  由v1<=v2得到   A1-B1*C1 + A2-B2*t <= A2-B2*C2 + A1-B1*t

  化简得到 B1*C1 + B2*t >= B2*C2 + B1*t

  那么在排序时直接用这条式子就行了。

 //#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <deque>
#include <map>
#include <algorithm>
#include <vector>
#include <iostream>
#define pii pair<int,int>
#define back que[rear-1]
#define INF 0x3f3f3f3f
#define LL long long
#define ULL unsigned long long
using namespace std;
const double PI = acos(-1.0);
const int N=;
struct node
{
int a, b, c;
double rate;
}seq[N];
int n, time, dp[N*];
int cmp(node a,node b)
{
int t2=a.c+b.c;
return b.b*b.c+a.b*t2>=a.b*a.c+b.b*t2;
}
int cal()
{
sort(seq+,seq+n+, cmp);
memset(dp,-,sizeof(dp));
dp[]=;
for(int i=; i<=n; i++)
for(int j=time; j>=seq[i].c; j--)
{
if( dp[j-seq[i].c]< ) continue;
int v=seq[i].a - j*seq[i].b;
dp[j]=max( dp[j], dp[j-seq[i].c]+v );
}
int ans=;
for(int i=time; i>=; i--)
ans=max(ans, dp[i]);
return ans;
} int main()
{
freopen("input.txt", "r", stdin);
int t;cin>>t;
while(t--)
{
scanf("%d%d",&n,&time);
for(int i=; i<=n; i++)
scanf("%d%d%d", &seq[i].a,&seq[i].b,&seq[i].c);
cout<<cal()<<endl;
}
return ;
}

AC代码

用官方题解的代码:

 //#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <deque>
#include <map>
#include <algorithm>
#include <vector>
#include <iostream>
#define pii pair<int,int>
#define back que[rear-1]
#define INF 0x3f3f3f3f
#define LL long long
#define ULL unsigned long long
using namespace std;
const double PI = acos(-1.0);
const int N=;
struct node
{
int a, b, c;
double rate;
}seq[N];
int n, time, dp[N*];
int cmp(node a,node b)
{
return a.rate>b.rate;
}
int cal()
{
sort(seq+,seq+n+, cmp);
memset(dp,-,sizeof(dp));
dp[]=;
for(int i=; i<=n; i++)
for(int j=time; j>=seq[i].c; j--)
{
if( dp[j-seq[i].c]< ) continue;
int v=seq[i].a - j*seq[i].b;
dp[j]=max( dp[j], dp[j-seq[i].c]+v );
}
int ans=;
for(int i=time; i>=; i--)
ans=max(ans, dp[i]);
return ans;
} int main()
{
//freopen("input.txt", "r", stdin);
int t;cin>>t;
while(t--)
{
scanf("%d%d",&n,&time);
for(int i=; i<=n; i++)
{
scanf("%d%d%d", &seq[i].a,&seq[i].b,&seq[i].c);
seq[i].rate=1.0*seq[i].b/seq[i].c;
}
cout<<cal()<<endl;
}
return ;
}

AC代码

HDU 5501 The Highest Mark (贪心+DP,经典)的更多相关文章

  1. HDU 5501 The Highest Mark 背包dp

    The Highest Mark Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  2. HDU 5501 The Highest Mark

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5501 The Highest Mark  Accepts: 32  Submissions: 193 ...

  3. HDU 5501——The Highest Mark——————【贪心+dp】

    The Highest Mark Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

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

    题意:类似cf的赛制,每道题目有A,B,C三个值,A表示初始分数,B表示每分钟题的分数会减少B,C表示做这道题需要C分钟,数据保证分数不会变为负数.现在给出比赛时长,问安排做题的顺序,求最大得分. 思 ...

  5. HDU 5501:The Highest Mark 01背包

    The Highest Mark  Accepts: 71  Submissions: 197  Time Limit: 2000/1000 MS (Java/Others)  Memory Limi ...

  6. HDU5501/BestCoder Round #59 (div.2)The Highest Mark dp+贪心

    The Highest Mark 问题描述 2045年的SD省队选拔,赛制和三十年前已是完全不同.一场比赛的比赛时间有 tt 分钟,有 nn 道题目. 第 ii 道题目的初始分值为 A_i(A_i \ ...

  7. HDU 2993 MAX Average Problem(斜率DP经典+输入输出外挂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2993 题目大意:给出n,k,给定一个长度为n的序列,从其中找连续的长度大于等于k的子序列使得子序列中的 ...

  8. hdu 1257 最少拦截系统【贪心 || DP——LIS】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  9. hdu5501 The Highest Mark

    Problem Description The SDOI in 2045 is far from what it was been 30 years ago. Each competition has ...

随机推荐

  1. CI框架3.0版本以后,前后台分离的方法。

    笔者认为,CI框架官方其实并没有考虑这个前后台分离的问题,所以没有官方的分离方法.而且,2.0版本的分离,也被官方认为这是一个bug.所以在前后台分离这个问题上,其实并不如thinkphp框架. 在C ...

  2. [小工具] C#多线程|匿名委托传参数|测试网站压力--升级版

    上次文章链接:http://www.sufeinet.com/thread-11-1-1.html写这些并不是不会用测试工具,也并不是无视测试工具,而是做为一个程序员希望用自己写的东西来完成一些功能, ...

  3. python unittest模块

    import unittest import random class Operation(object): def __init__(self, num1=0, num2=0): if not (0 ...

  4. iOS风格的弹出框(alert,prompt,confirm)

    前两天,自己写了一个简单的插件,在移动端使用,不管是安卓手机还是iOS系统的手机,弹出框统一使用iOS风格的. 该弹出框是依赖于jQuery的,当然也可以将用jq写的几句代码转换为原生代码. 今天把代 ...

  5. katalon studio配置git与git项目创建

    katalon 是一款在2015年诞生的可以安装在windows.macOS.linux操作系统上,基于selenium 和 Appium 测试框架,并集成了这些框架的优点的自动化测试工具.关于这个工 ...

  6. CentOS6.7 i686上安装JDK7

    内核版本: [root@heima01 java]# uname -a Linux heima01 2.6.32-573.el6.i686 #1 SMP Thu Jul 23 12:37:35 UTC ...

  7. 使用echo命令向文件写入内容

    0.前言     本文总结如何使用echo命令向文件中写入内容,例如使用echo指令覆盖文件内容,使用echo指令向文件追加内容,使用echo指令往文件中追加制表符.     echo向文件中输出内容 ...

  8. vue教程3-webpack搭建项目

    vue-cli https://cli.vuejs.org/zh/ vue-cli是vue的命令行工具,对于创建项目,安装各种组件,运行项目都极为方便,是在开发vue中的必备工具 vue-cli基于n ...

  9. LVM逻辑卷基本概念以及相关操作

    一.LVM概念 LVM(Logical Vloume Manager):它是linux环境下对磁盘进行管理的一种机制,正常挂载的磁盘在磁盘资源快要耗尽时,无法动态拉伸增加资源,或由于特殊情况需要动态缩 ...

  10. Django之用户认证—auth模块

    用户认知———auth模块 目录: auth模块 User对象 实例 扩展默认的auth_user表 - 创建超级用户 - python3 manager.py createsuperuser - 认 ...