题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5501
The Highest Mark
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1357 Accepted Submission(s): 576
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.
Sample Input
1 4 10 110 5 9 30 2 1 80 4 8 50 3 2
Sample Output
88
题目分析:
一开始做的时候以为这是个贪心问题,把得分直接通过a-b*c算出来,然后按照一定顺序排列取最优结果。忽略了第二题的时间应该要加上前一题的时间。所以要找出dp的规则,假设有题目a1,b1,b1和a2,b2,c2,如果先做1再做2的得分是a1-b1*c1+a2-b2*(c1+c2),如果先做2在做1的得分是a2-b2*c2+a1-b1*(c1+c2),所以只要b1*c2>=b2*c1第一题分数要比第二题分数高。
#include<iostream>
#include<algorithm>
#include<memory.h>
using namespace std;
struct que{
int a;
int b;
int time;
}quiz[1010];
bool cmp(que x,que y)
{
return x.b*y.time>x.time*y.b;
}
int dp[3010],vis[3050];
//不可能并行回答题目
int main(void)
{
int T;
cin>>T;
while(T--)
{
memset(dp,0,sizeof(dp));
memset(vis,0,sizeof(vis));
int n,t;
cin>>n>>t;
for(int i=1;i<=n;i++)
{
cin>>quiz[i].a>>quiz[i].b>>quiz[i].time;
}
sort(quiz+1,quiz+n+1,cmp);
for(int i=1;i<=n;i++)
{
for(int j=t;j>=0;j--)
{
if(j>=quiz[i].time)
{
int score = quiz[i].a-quiz[i].b*(vis[j-quiz[i].time]+quiz[i].time);
if(dp[j-quiz[i].time]+score>dp[j]){
dp[j]=dp[j-quiz[i].time]+score;
vis[j]=vis[j-quiz[i].time]+quiz[i].time;
}
}
}
}
cout<<dp[t]<<endl;
}
}