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;
}

  

最新文章

  1. iOS---The maximum number of apps for free development profiles has been reached.
  2. C++ STL--stack/queue 的使用方法
  3. codeforces B.Fixed Points
  4. Android中editText使用报错
  5. java.util.TimeZone 新加方法 getTimeZone(ZoneId zoneId) 导致的问题
  6. javascript 依次输入自动定焦框
  7. webconfig和appconfig中出现特殊字符如何处理
  8. installshield basic msi 更新时覆盖不了上一个版本文件解决方案1
  9. css优先级判断
  10. python中os模块path.abspath()返回的并不是绝对值,而是个错误的不存在的拼接地址
  11. 原生javascript与jquery 的比较
  12. 【Python】functools.wraps定义函数装饰器
  13. virtualbox 提示 vboxclient the virtualbox kernel service is not running
  14. Elasticsearch VS Solr
  15. Asp.net中,从弹出窗体取选择值(转)
  16. [学习笔记]Javaweb开发视频教程之Tomcat9配置
  17. Ubuntu14.04+Dell 7060安装无线/有线网络驱动
  18. java子类继承关系
  19. java后台解析前端传来的json
  20. 通过Eureka自带REST API强行剔除失效服务

热门文章

  1. altium designer 中的top/bottom solder和top/bottom paste mask
  2. Oracle中生成UUID
  3. centos6.5安装tomcat7.0教程(二)
  4. AVI编码器
  5. C语言入门题
  6. PopupWindow 防微信弹出右 侧窗体(继承PopupWindow )
  7. service使用handler与Activity沟通的两种方法
  8. Leetcode:206. Reverse Linked List
  9. 【转】Subversion快速入门教程-动画演示
  10. 【Sping管理bean的原理】