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
 

这题是贪心和背包问题,首先考虑如果已经确定要做的题,那么怎样的做题顺序能使分数减少最少,这里我们假设有i和i+1,那么如果先做i后做i+1,分数减少c[i+1]*b[i]+K(K是常数),否则分数减少c[i]*b[i+1]+K.那么如果是第二种减少的少,则c[i]*b[i+1]<c[i+1]*b[i],即c[i+1]/b[i+1]>c[i]/b[i],所以如果对于相邻的两个数,如果c[i+1]/b[i+1]>c[i]/b[i],那么就要交换顺序,这样我们就可以排个序,然后背包就行了。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define ll int
#define inf 0x7fffffff
#define maxn 1006
struct node{
int a,b,c;
double num;
}d[maxn];
int dp[4*maxn];
bool cmp(node a,node b){
return a.num<b.num;
} int main()
{
int n,m,i,j,T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%lld%lld%lld",&d[i].a,&d[i].b,&d[i].c);
d[i].num=(double)d[i].c/(double)d[i].b; }
sort(d+1,d+1+n,cmp);
memset(dp,0,sizeof(dp));
for(i=1;i<=n;i++){
for(j=m;j>=d[i].c;j--){
dp[j]=max(dp[j],dp[j-d[i].c ]+d[i].a-j*d[i].b);
}
}
int maxx=-1;
for(i=1;i<=m;i++)maxx=max(maxx,dp[i]);
printf("%d\n",maxx);
}
return 0;
}

hdu5501 The Highest Mark的更多相关文章

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

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

  2. 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 ...

  3. The Highest Mark(01背包)

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

  4. HDU 5501 The Highest Mark

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

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

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

  6. HDU 5501:The Highest Mark 01背包

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

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

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

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

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

  9. SDOI(队列)

    SDOI Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Sub ...

随机推荐

  1. 【Flutter】功能型组件之跨组件状态共享

    前言   在Flutter开发中,状态管理是一个永恒的话题.   一般的原则是:如果状态是组件私有的,则应该由组件自己管理:如果状态要跨组件共享,则该状态应该由各个组件共同的父元素来管理.   对于组 ...

  2. P1220 关路灯(区间规划)

    题目描述 某一村庄在一条路线上安装了n盏路灯,每盏灯的功率有大有小(即同一段时间内消耗的电量有多有少).老张就住在这条路中间某一路灯旁,他有一项工作就是每天早上天亮时一盏一盏地关掉这些路灯. 为了给村 ...

  3. python—base64

    今天在写题时,执行脚本又报错了 脚本如下 #! /usr/bin/env python3 # _*_ coding:utf-8 _*_ import base64 # 字典文件路径 dic_file_ ...

  4. px转rem的填坑之路

    这是要为一个vue项目做自适应,设计稿是1920*1080的,要适应各种手机.ipad.3840*2160的超大屏,所以就选择了rem,包用的是 postcss-pxtorem 在适配的时候遇到了很多 ...

  5. Docker相关简介以及使用方法

    Docker: 可以把它看作是一个软件,在这个软件当中呢,还可以安装其他的软件,还可以把软件所需要的环境依赖一起添加进来,这样让开发人员的程序在不同的环境当中都可以流转起来,避免了程序出现" ...

  6. apache状态显示报错AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdo...is message

    今天启动apache查看状态发现报错,说不能确认服务器完全确认域名,以下是报错内容: [root@localhost ~]# service httpd status Redirecting to / ...

  7. jQuery 勾选启用输入框

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. The router relies on a tree structure which makes heavy use of common prefixes, it is basically a compact prefix tree (or just Radix tree).

    https://github.com/julienschmidt/httprouter/

  9. get_or_create update_or_create

    django/query.py at master · django/django https://github.com/django/django/blob/master/django/db/mod ...

  10. SRE SLO On-Call 流程机制 系统稳定性

    开篇词|SRE是解决系统稳定性问题的灵丹妙药吗? https://time.geekbang.org/column/article/212686 这两年,近距离地接触了很多不同类型.不同规模的企业 I ...