hdu5501 The Highest Mark
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.
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.
4 10
110 5 9
30 2 1
80 4 8
50 3 2
这题是贪心和背包问题,首先考虑如果已经确定要做的题,那么怎样的做题顺序能使分数减少最少,这里我们假设有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的更多相关文章
- HDU5501/BestCoder Round #59 (div.2)The Highest Mark dp+贪心
The Highest Mark 问题描述 2045年的SD省队选拔,赛制和三十年前已是完全不同.一场比赛的比赛时间有 tt 分钟,有 nn 道题目. 第 ii 道题目的初始分值为 A_i(A_i \ ...
- 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 ...
- The Highest Mark(01背包)
The Highest Mark Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- 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】
The Highest Mark Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- HDU 5501:The Highest Mark 01背包
The Highest Mark Accepts: 71 Submissions: 197 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- hdu 5501 The Highest Mark(贪心+01背包)
题意:类似cf的赛制,每道题目有A,B,C三个值,A表示初始分数,B表示每分钟题的分数会减少B,C表示做这道题需要C分钟,数据保证分数不会变为负数.现在给出比赛时长,问安排做题的顺序,求最大得分. 思 ...
- HDU 5501 The Highest Mark (贪心+DP,经典)
题意: 有n道题目,每道题目的初始分数为Ai,分数每分钟减少Bi,完成此题需要Ci分钟,问在t分钟内最多能获得多少分? 思路: 好题~ 如果没有B的话,就是一道裸的01背包的题目了.每道题目的得分为: ...
- SDOI(队列)
SDOI Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Sub ...
随机推荐
- 【Flutter】可滚动组件之ListView
前言 它可以沿一个方向线性排布所有子组件,并且它也可以支持基于Sliver的延迟构建模型. 接口描述 ListView({ Key key, // 可滚动widget公共参数 Axis scrollD ...
- leetcode-222完全二叉树的节点个数
题目 给出一个完全二叉树,求出该树的节点个数. 说明: 完全二叉树的定义如下:在完全二叉树中,除了最底层节点可能没填满外,其余每层节点数都达到最大值,并且最下面一层的节点都集中在该层最左边的若干位置. ...
- ubuntu 上搭建 go的开发环境 vscode
原文链接: https://astaxie.gitbooks.io/build-web-application-with-golang/zh/01.4.html 原本我是在windows下进行go的环 ...
- 【IMPDP】ORA-31655
出现ora-31655错误的情况是因为不是同一个schema,导致的问题产生 解决的方法; 在导入语句最后添加上remap_schema=old:new 着old是原schema,也就是导出的用户名, ...
- cut和tr命令的联合使用
cut的-d选项只能是单个字符,而对于多个连续相同字符分隔的字段,单凭cut命令是达不到想要的效果的,特别是多个连续空格分隔时. 但借助tr -s的压缩重复字符功能,可以将多个连续空格压缩为一个空格, ...
- kubernetes之为每个命名空间的pod设置默认的requests以及limits
一 为啥需要为命名空间里面添加pod添加默认的requests和limits? 通过前面的学习我们已经知道,如果节点上面的pod没有设置requests和limits,这些容器就会受那些设置了的控制 ...
- Vitis下载安装尝试
Vitis下载安装记录 一.下载安装 文章目录 一.下载安装 提示:以下是本篇文章正文内容,下面案例可供参考 一.下载安装 首先本次下载主要使用的是linux系统,所以我们先看一下Vitis支持的li ...
- Hadoop2.7.7阿里云安装部署
阿里云的网络环境不需要我们配置,如果是在自己电脑上的虚拟机,虚拟机的安装步骤可以百度.这里是单机版的安装(也有集群模式的介绍)使用Xshell连接阿里云主机,用命令将自己下载好的安装包上传到服务器 # ...
- django之orm单表查询
这几天重新学习了一下django的orm,以此作为记录来分享. Part1:修改配置,生成表 在写数据和查数据之前,首先先得把django配置一下,具体配置如下: 1.先在公共项目的settings中 ...
- Bagging和Boosting的介绍及对比
"团结就是力量"这句老话很好地表达了机器学习领域中强大「集成方法」的基本思想.总的来说,许多机器学习竞赛(包括 Kaggle)中最优秀的解决方案所采用的集成方法都建立在一个这样的假 ...