HDOJ 5501The Highest Mark(贪心+动态规划)
来源:互联网 发布:cms架构图 编辑:程序博客网 时间:2024/05/16 07:10
The Highest Mark
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 701 Accepted Submission(s): 290
Problem Description
The SDOI in 2045 is far from what it was been 30 years ago. Each competition has t minutes and n problems.
Theith 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 onx 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 spendCi(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
If someone solves a problem on
dxy who attend this competition with excellent strength, can measure the time of solving each problem exactly.He will spend
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 linen(1≤n≤1000) and t(1≤t≤3000) for the number of problems and the time limitation of this competition.
There aren 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 problem2 and then solve problem 1 he will get 88 marks. Higher than any other order.
For each testcase, there are two integers in the first line
There are
Hint:
First to solve problem
Output
For each testcase output a line for an integer, for the highest mark dxy will get in this competition.
Sample Input
14 10110 5 930 2 180 4 850 3 2
Sample Output
88
Source
BestCoder Round #59 (div.1)
题解: 这道题考察的是贪心思想和动态规划。
首先我们考虑,假如我们已经确定了要做哪些题目,按什么顺序做这些题目最好。
假设已经确定了要做其中的m道题,某一个方案中做题的顺序是依次做x1,x2→xm,那么对于这个方案中任意的相邻两项xi,xi+1,考虑交换这两项的顺序,方案是否会变得更优,交换方案中的相邻两项,只会对这两道题的得分有影响,对其余的题目不会产生影响。
如果不交换这两项,损失的分数是 Cxi∗Bxi+1+K,如果交换这两项,损失的分数是Cxi+1∗Bxi+K (K是一个常数) 所以只需要判断是否 Cxi∗Bxi+1≤Cxi+1∗Bxi+K,如果此不等式成立,那么应该交换这两项。对上式移项得 Bxi+1/Cxi+1>Bxi/Cxi。所以对于一个确定的题目集合,做题的最优顺序只与每道题目的Bi/Ci有关,按每道题目扣分速度与做题时间的比值排序,按照比值从大到小做题。
因此我们先对所有的题目按照这个比值进行排序,接下来,只要按照排好的顺序,选择做哪些题目就可以了。这相当于一个简单的“背包问题”,使用动态规划来解决。dpi表示恰好用了i分钟的最高得分。状态转移方程为dpi=max1≤j≤ndpi−Cj+Aj−(i∗Bj)。
最终答案是max0≤i≤tdpi。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 3010;int dp[N];struct node{int a, b, c;bool operator<(const node & X) const {return b * X.c > c * X.b;}}Node[N];int main() {int T;scanf("%d", &T);while (T--) {int n, t;scanf("%d%d", &n, &t);for (int i = 0; i < n; ++i) scanf("%d%d%d", &Node[i].a, &Node[i].b, &Node[i].c);sort(Node, Node + n);int a, b, c;memset(dp, -1, sizeof(dp));dp[0] = 0;for (int i = 0; i < n; ++i) {a = Node[i].a;b = Node[i].b;c = Node[i].c;for (int j = a / b - c; j >= 0; --j) {if (j + c <= t && dp[j + c] < dp[j] + a - (j + c) * b)dp[j + c] = dp[j] + a - (j + c) * b;}}int ans = 0;for (int i = 1; i <= t; ++i)if (ans < dp[i]) ans = dp[i];printf("%d\n", ans);}return 0;}
0 0
- HDOJ 5501The Highest Mark(贪心+动态规划)
- hdu5501 The Highest Mark 贪心+动态规划
- hdoj 5501 The Highest Mark 【贪心 + 0-1背包】
- hdoj 5501 The Highest Mark 【贪心 + 0-1背包】
- hdoj 5501The Highest Mark【贪心+0-1背包】
- hdu 5501 The Highest Mark(贪心+背包)
- The Highest Mark hdu 5501 贪心+背包
- HDOJ 题目5501 The Highest Mark(贪心+01背包变形)
- 贪心+dp hdu5501 The Highest Mark
- HDU5501 The Highest Mark 贪心+DP
- hdu 5501 The Highest Mark
- HDU 5501:The Highest Mark 01背包
- hdu(5501)——The Highest Mark
- hdu5501 The Highest Mark
- BC#59 The Highest Mark
- The Highest Mark_hdu5501_dp+贪心
- hdu 5501 The Highest Mark(变形01背包)
- hdu5501The Highest Mark(贪心+背包,好题)
- 网站域名的选择
- Jsonlib实现Json字符串和Java对象的互相转换
- Java:单例模式的七种写法
- Android 项目实践(六)——开机动画的实现
- 关于distinct 和group by的去重逻辑浅析
- HDOJ 5501The Highest Mark(贪心+动态规划)
- iOS网络通信-NSURLConnection
- RHEL6下禁用selinux的方法
- Shell编程
- 8.1 计时器的基本知识
- hdu 4474 Yet Another Multiple Problem BFS+同余判重 ★★★★
- Django框架学习-Forms篇
- 携程第二春去哪儿 美大再度陷入内忧外患
- Flex中的Array和ArrayCollection