HDU 5501——The Highest Mark——————【贪心+dp】
The Highest Mark
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 630 Accepted Submission(s): 260
The ith problem with the original mark of Ai(Ai≤106),and it decreases Bi by each minute. It is guaranteed that it does not go to minus when the competition ends. For example someone solves the ith problem after x minutes of the competition beginning. He/She will get Ai−Bi∗x marks.
If someone solves a problem on x minute. He/She will begin to solve the next problem on x+1 minute.
dxy who attend this competition with excellent strength, can measure the time of solving each problem exactly.He will spend Ci(Ci≤t) minutes to solve the ith problem. It is because he is so godlike that he can solve every problem of this competition. But to the limitation of time, it's probable he cannot solve every problem in this competition. He wanted to arrange the order of solving problems to get the highest mark in this competition.
For each testcase, there are two integers in the first line n(1≤n≤1000) and t(1≤t≤3000) for the number of problems and the time limitation of this competition.
There are n lines followed and three positive integers each line Ai,Bi,Ci. For the original mark,the mark decreasing per minute and the time dxy of solving this problem will spend.
Hint:
First to solve problem 2 and then solve problem 1 he will get 88 marks. Higher than any other order.
这道题考察的是贪心思想和动态规划。
出题人中间可能是笔误,应该是 “如果此不等式不成立,那么应该交换这两项。“才对。或者我们假设此不等式成立,那么移项后发现(Bxi+1 / Cxi+1 <= Bxi / Cxi)也是应该按照(B/C)值从大到小的顺序选择。
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<vector>
using namespace std;
typedef long long INT;
const int maxn = 1e5+200;
struct Problem{
INT a,b,c;
}pros[maxn];
INT dp[maxn];
bool cmp(Problem aa,Problem bb){
return (aa.b*1.0 / aa.c) > (bb.b*1.0 / bb.c); // >
}
int main(){
int n,t,T;
while(T--){
scanf("%d%d",&n,&t);
memset(dp,0,sizeof(dp));
for(int i = 1; i <= n; i++){
scanf("%lld%lld%lld",&pros[i].a,&pros[i].b,&pros[i].c);
}
sort(pros+1, pros+1+n, cmp);
for(int i = 1; i <= n; i++){
for(int j = t; j >=pros[i].c ; j--){
dp[j] = max(dp[j], dp[j-pros[i].c] + pros[i].a - (j * pros[i].b) );
}
}
INT ans = dp[0];
for(int i = 1; i <= t; i++){
ans = max(ans, dp[i]);
}
printf("%lld\n",ans);
}
return 0;
}
HDU 5501——The Highest Mark——————【贪心+dp】的更多相关文章
- 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 ...
- HDU 5501 The Highest Mark
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5501 The Highest Mark Accepts: 32 Submissions: 193 ...
- HDU 5501 The Highest Mark (贪心+DP,经典)
题意: 有n道题目,每道题目的初始分数为Ai,分数每分钟减少Bi,完成此题需要Ci分钟,问在t分钟内最多能获得多少分? 思路: 好题~ 如果没有B的话,就是一道裸的01背包的题目了.每道题目的得分为: ...
- hdu 5501 The Highest Mark(贪心+01背包)
题意:类似cf的赛制,每道题目有A,B,C三个值,A表示初始分数,B表示每分钟题的分数会减少B,C表示做这道题需要C分钟,数据保证分数不会变为负数.现在给出比赛时长,问安排做题的顺序,求最大得分. 思 ...
- HDU 5501:The Highest Mark 01背包
The Highest Mark Accepts: 71 Submissions: 197 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- HDU5501/BestCoder Round #59 (div.2)The Highest Mark dp+贪心
The Highest Mark 问题描述 2045年的SD省队选拔,赛制和三十年前已是完全不同.一场比赛的比赛时间有 tt 分钟,有 nn 道题目. 第 ii 道题目的初始分值为 A_i(A_i \ ...
- hdu 1257 最少拦截系统【贪心 || DP——LIS】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- hdu5501 The Highest Mark
Problem Description The SDOI in 2045 is far from what it was been 30 years ago. Each competition has ...
- 【BZOJ-3174】拯救小矮人 贪心 + DP
3174: [Tjoi2013]拯救小矮人 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 686 Solved: 357[Submit][Status ...
随机推荐
- 5.JasperReports学习笔记5-其它数据生成动态的报表(WEB)
转自:http://www.blogjava.net/vjame/archive/2013/10/12/404908.html 一.空数据(Empty Datasources) 就是说JRXML文件里 ...
- js 取get过来的数据
function getQuery(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&am ...
- Javascript作用域和变量提升
下面的程序是什么结果? var foo = 1; function bar() { if (!foo) { var foo = 10; } alert(foo); } bar(); 结果是10: 那么 ...
- Ubuntu W: GPG 错误:下列签名无效: BADSIG 84DBCE2DCEC45805 Launchpad PPA fo
Ubuntu12.04 安装R语言的时候出现的报错. 研究了两个晚上,解决办法如下,跟参考贴有点出入: ############################################### ...
- 转:JMeter整合InfluxDB,Grafana让测试结果实时显示
软件版本: apache-jmeter-2.13.tgz grafana-2.1.1-1.x86_64.rpm influxdb-0.8.8-1.x86_64.rpm 虽然官方不在支持influxdb ...
- SQL Server中通过设置非聚集索引(Non-Clustered index)来达到性能优化的目的
首先我们一下,在SQL Server 2014 Management Studio中,如何为一张表设置Non-Clustered index 具体可以参考 https://docs.microsof ...
- hdu1052
#include <iostream>#include<algorithm>#include<queue>#include<stack>#include ...
- 【Qt官方例程学习笔记】Application Example(构成界面/QAction/退出时询问保存/用户偏好载入和保存/文本文件的载入和保存/QCommandLineParser解析运行参数)
The Application example shows how to implement a standard GUI application with menus, toolbars, and ...
- 【关于msyql5.6创建存储过程的一些记录】
-- 秒杀执行存储过程DELETE $$ -- console的结束符号由;转换成 $$-- in输入参数:out:输出参数-- ROW_COUNT():返回上条dml影响的条数: 小于0:sql语句 ...
- RDS mysql 与ECS自建mysql做主从备份
由于公司要组建一个数据中心,简而言之就是把各个地方的数据都同步到一个地方,做BI建模和数据分析. 一般来说这种需求是由hadoop来实现的,但由于预算不够..所以,来个low点的办法吧 以下主要是讲r ...