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

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

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.

 
Input
There is an positive integer T(T≤10) in the first line for the number of testcases.(the number of testcases with n>200 is no more than 5)

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.

 
Output
For each testcase output a line for an integer, for the highest mark dxy will get in this competition.
 
Sample Input
1
4 10
110 5 9
30 2 1
80 4 8
50 3 2
 
Sample Output
88
 
Source
 
 
题目大意:n个问题,每个问题开始有个分值A,以及每分钟减少的分值B,解出该问题需要的时间C。问你在t分钟的时间内能得到的分值最多是多少。
 
解题思路:

这道题考察的是贪心思想和动态规划。

出题人中间可能是笔误,应该是  “如果此不等式不成立,那么应该交换这两项。“才对。或者我们假设此不等式成立,那么移项后发现(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】的更多相关文章

  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,经典)

    题意: 有n道题目,每道题目的初始分数为Ai,分数每分钟减少Bi,完成此题需要Ci分钟,问在t分钟内最多能获得多少分? 思路: 好题~ 如果没有B的话,就是一道裸的01背包的题目了.每道题目的得分为: ...

  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 1257 最少拦截系统【贪心 || DP——LIS】

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

  8. hdu5501 The Highest Mark

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

  9. 【BZOJ-3174】拯救小矮人 贪心 + DP

    3174: [Tjoi2013]拯救小矮人 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 686  Solved: 357[Submit][Status ...

随机推荐

  1. 一 Akka学习 - actor

    (引用 http://shiyanjun.cn/archives/1168.html) 一: 什么是Akka? Akka是JAVA虚拟机JVM平台上构建高并发.分布式和容错应用的工具包和运行时,是一个 ...

  2. bzoj4403

    组合数学 我好菜啊 想到dp去了... 事实上对于固定长度的数列,我们只用考虑选了哪些数就行了,所以这个就是$C(n+m-1,m-1)$ 也就是$n$个数,划分成$m$段且允许空的方案数 然后变成$\ ...

  3. PWA PSI statusingclient.UpdateStatus更新任务页面的AssnCustomFields的TextValue值

    1.注意Changesxml格式和下面一定要一样 2.CustomFieldGuid和CustomFieldName都不能少,自定义域的uid和name其中uid或者是MD_PROP_UID_SECO ...

  4. 关于web中注册倒数的问题(亲测)

    <title></title>    <script type="text/javascript">        var leftSecond ...

  5. url传参解决中文乱码

    跳转前: window.open("http://localhost:9728/content/agent/devolution.html?search_agent=" + enc ...

  6. 写一个c程序辨别系统是16位or32位

    方法: 32位处理器就是一次只能处理32位,也就是4个字节的数据,虚拟地址空间的最大大小是4G,而64位处理一次就能处理64位,即8个字节的数据,最大虚拟地址空间的最大大小是16T.最明显的是指针大小 ...

  7. 【总结整理】javascript的函数在if中调用时是否加括号---与.net的不同之处

    javascript的函数调用时是否加括号 if(event.preventDefault){ event.preventDefault(); if判断条件里面不要加括号,不加括号是应该以属性形式,i ...

  8. assert.strictEqual()

    assert.strictEqual(actual, expected[, message]) 使用全等运算符(===)测试 actual 参数与 expected 参数是否全等. // 格式 ass ...

  9. 在Eclipse里面配置Struts2

    下面介绍在Eclipse里面配置Struts2 下载Struts2的压缩包 我下载的是2.3.32版本 解压之后如图所示 apps目录:Struts2的范例 docs目录:Struts2的文档 lib ...

  10. HDU 5862 Counting Intersections (离散化+扫描线+树状数组)

    题意:给你若干个平行于坐标轴的,长度大于0的线段,且任意两个线段没有公共点,不会重合覆盖.问有多少个交点. 析:题意很明确,可是并不好做,可以先把平行与x轴和y轴的分开,然后把平行y轴的按y坐标从小到 ...