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 ...
随机推荐
- JVM-Class文件的结构
Class类文件的结构 Class文件是一株以8个字节为单位的二进制流.各个数据项目严格按照顺序紧凑的排列在文件之中,中间没有任何的分隔符,当遇到占用的空间大于8个字节时,会按照高位在前的方式进行分割 ...
- Spark Streaming处理Flume数据练习
把Flume Source(netcat类型),从终端上不断给Flume Source发送消息,Flume把消息汇集到Sink(avro类型),由Sink把消息推送给Spark Streaming并处 ...
- 【RAC】安装rac的时候。报错checking for oracle home incompatibilities failed
背景:由于oracle安装的时候中途出现了问题,解决过后,发现报错了 图形化安装的时候,有这个问题出现 解决办法: 删除安装过的所有缓存,和文件即可 1.删除ORACLE_BASE下的所有文件 2.删 ...
- LeetCode501.二叉搜索树中的众数
题目,本题未做出,还有很多要学习 class Solution { public: vector<int>ans; int base,count,maxCount; void update ...
- 萌新入门之python基础语法
首先我们先了解一些python最最基础的入门 1.标识符 定义:我们写代码的时候自己取得名字比如项目名,包名,模块名这些: 规范:1.数字/字母/下划线组成,不能以数字开头 2.起名字要见名知意 3. ...
- postgresql-12编译安装
1 准备环境 修改yum源 mkdir -p /etc/yum.bak mv /etc/yum.repos.d/* /etc/yum.bak/ &&\ curl -o /etc/yum ...
- Py变量,递归,作用域,匿名函数
局部变量与全局变量 全局变量:全局生效的变量,在顶头的,无缩进的定义的变量. 局部变量:函数内生效的变量,在函数内定义的变量. name='1fh' def changename(): name='s ...
- 登陆的时候出现javax.xml.bind.DatatypeConverter错误
错误详情: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/Da ...
- Qt 自动化测试Test cutedriver
示例 https://github.com/nomovok-opensource/cutedriver-examples CuteDriver examples This repository con ...
- (转载)微软数据挖掘算法:Microsoft 决策树分析算法(1)
微软数据挖掘算法:Microsoft 目录篇 介绍: Microsoft 决策树算法是分类和回归算法,用于对离散和连续属性进行预测性建模. 对于离散属性,该算法根据数据集中输入列之间的关系进行预测. ...