The Highest Mark_hdu5501_dp+贪心
来源:互联网 发布:全排列算法详解 编辑:程序博客网 时间:2024/05/03 10:22
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.
Source
BestCoder Round #59 (div.1)
Analysis
不难想出最优解肯定是连续做完某些题目,那么问题就是如何找到最优的做题顺序
考虑物品
当
当
先贪心,拆开来去重按照
Code
#include <cstdio>#include <cstring>#include <algorithm>#define ll long long#define N 1501#define M 4001using namespace std;struct num{ll a,b,c;}t[N];ll f[M];ll max(ll x,ll y){return x<y?y:x;}int cmp(num x,num y){return x.c*y.b<x.b*y.c;}int main(){ int T; scanf("%d",&T); while (T--) { int n,m; ll ans=0; scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) scanf("%lld%lld%lld",&t[i].a,&t[i].b,&t[i].c); for (int i=0;i<=m+1;i++) f[i]=0; sort(t+1,t+n+1,cmp); for (int i=1;i<=n;i++) for (int j=m;j>=t[i].c;j--) { f[j]=max(f[j],f[j-t[i].c]+t[i].a-t[i].b*j); ans=max(f[j],ans); } printf("%lld\n",ans); } return 0;}
- The Highest Mark_hdu5501_dp+贪心
- 贪心+dp hdu5501 The Highest Mark
- hdu5501 The Highest Mark 贪心+动态规划
- hdu 5501 The Highest Mark(贪心+背包)
- The Highest Mark hdu 5501 贪心+背包
- HDU5501 The Highest Mark 贪心+DP
- hdoj 5501 The Highest Mark 【贪心 + 0-1背包】
- HDOJ 5501The Highest Mark(贪心+动态规划)
- hdoj 5501 The Highest Mark 【贪心 + 0-1背包】
- hdoj 5501The Highest Mark【贪心+0-1背包】
- HDOJ 题目5501 The Highest Mark(贪心+01背包变形)
- hdu5501 The Highest Mark
- hdu 5501 The Highest Mark
- BC#59 The Highest Mark
- hdu5501The Highest Mark(贪心+背包,好题)
- HDU5501The Highest Mark(贪心+背包)
- HDU 5501:The Highest Mark 01背包
- hdu(5501)——The Highest Mark
- 关于递归实现过程的详解
- AspectJ 切面获取参数名称和参数
- 关于利用Tomcat创建一个Java Web项目的部署
- Python中json格式数据的编码和解码
- Leetcode 138 Copy List with Random Pointer
- The Highest Mark_hdu5501_dp+贪心
- hdu1561 the more , the better 树形dp
- Label显示不同颜色、字体的文字
- TestNG系列-第7章 YAML
- grub
- weka中Apriori算法实现与分析
- HDU-1003 Max Sum
- pygrametl的使用--python的ETL包
- Linux C编程--sizeof面试题选