贪心+dp--hdu5501(经典题)
来源:互联网 发布:nginx配置域名绑定ip 编辑:程序博客网 时间:2024/05/21 19:49
The Highest Mark
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)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 theith 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)
Recommend
hujie
这道题题意:每道题目有A,B,C三个值,A表示初始分数,B表示每分钟题的分数会减少B,C表示做这道题需要C分钟,数据保证分数不会变为负数。现在给出比赛时长,问安排做题的顺序,求最大得分。
思路:首先感觉有点像01背包,但是01背包在dp的时候与选择物品的顺序无关,但是这道题在动态规划的时候,当前选择做的题的用时对后面做的题的得分有影响,所以dp时必然有前后顺序,所以要么就是状态压缩,要么就是之前就把这些题目排序了,使得后面是有序的。状压不用考虑了因为数据太大,所以我们考虑要如何排序。接下来就是该如何贪心了。
现在有A1,B1,C1和A2,B2,C2这两道题,如果先做1再做2的得分是A1-B1*C1+A2-B2*(C1+C2),如果先做2在做1的得分是A2-B2*C2+A1-B1*(C1+C2),令先做1再做2的得分更高些,那么有A1-B1*C1+A2-B2*(C1+C2) >= A2-B2*C2+A1-B1*(C1+C2),解得B1*C2>=B2*C1所以,只要B1*C2>=B2*C1,那么先做题1再做题2的分数就会更高。
所以,我们只需要根据这个来排序,再做dp,就能得到答案了.代码:
现在有A1,B1,C1和A2,B2,C2这两道题,如果先做1再做2的得分是A1-B1*C1+A2-B2*(C1+C2),如果先做2在做1的得分是A2-B2*C2+A1-B1*(C1+C2),令先做1再做2的得分更高些,那么有A1-B1*C1+A2-B2*(C1+C2) >= A2-B2*C2+A1-B1*(C1+C2),解得B1*C2>=B2*C1所以,只要B1*C2>=B2*C1,那么先做题1再做题2的分数就会更高。
所以,我们只需要根据这个来排序,再做dp,就能得到答案了.代码:
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;struct node{int a,b,c;};node p[1005];int dp[3005];int vis[3005];int n,m;bool cmp(node x,node y) //排序{return x.b*y.c>x.c*y.b;}int main(){int T,i,j;scanf("%d",&T);while(T--){scanf("%d%d",&n,&m);for(i=1;i<=n;i++){scanf("%d%d%d",&p[i].a,&p[i].b,&p[i].c);}sort(p+1,p+n+1,cmp);memset(dp,0,sizeof(dp));memset(vis,0,sizeof(vis)); for(i=1;i<=n;i++) //dp{for(j=m;j>=0;j--){if(j>=p[i].c){int score=p[i].a-p[i].b*(vis[j-p[i].c]+p[i].c);if(dp[j-p[i].c]+score>dp[j]){dp[j]=dp[j-p[i].c]+score;vis[j]=vis[j-p[i].c]+p[i].c;}}}}printf("%d\n",dp[m]);}return 0;}
0 0
- 贪心+dp--hdu5501(经典题)
- 贪心+dp hdu5501 The Highest Mark
- HDU5501贪心加DP零一背包
- HDU5501 The Highest Mark 贪心+DP
- hdu5501 背包+贪心
- HDU5501
- hdu5501
- hdu5501
- hdu5501 The Highest Mark 贪心+动态规划
- [leetcode] 134 Gas Station(经典dp || 贪心)
- DP经典5题 【DP】
- 经典问题-活动选择问题-DP和贪心
- 经典问题-活动选择问题-DP和贪心
- POJ 2057 The Lost House 经典树形DP+贪心
- DP经典5题
- 树形DP经典题
- DP经典5题
- poj1952(经典dp题)
- C++两个栈实现一个队列
- 《我不是潘金莲》--中国式的荒唐
- Dijkstra's 算法
- 【Web前端】$(document).ready(function(){}) 和 $(window).on("load",function(){}) 的异同
- 文章标题
- 贪心+dp--hdu5501(经典题)
- arduino简易流水灯(新手之路)
- Oracle的UNDO表空间管理总结
- 电信天邑TEWA-300EA光猫破解, 解绑iTV口, 使用iTV口上网
- JavaScript取各个位数的方法
- 滑雪教程-新手必看(上)
- B. Arpa’s obvious problem and Mehrdad’s terrible solution #383 B
- JavaScript 正则表达式
- Android混淆从入门到精通