hdoj 5501The Highest Mark【貪心+0-1揹包】

The Highest Mark

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 885    Accepted Submission(s): 368


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(Ai106),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 AiBix 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(Cit) 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(T10) 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(1n1000) and t(1t3000) 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
 

Source
 

Recommend
hujie   |   We have carefully selected several similar problems for you:  5659 5658 5657 5656 5655 
 

Statistic | Submit | Discuss | Note

代碼:
//貪心+0-1揹包 
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct node
{
	int a,b,c;
}mp[1005];
int cmp(node u,node v)
{
	return u.b*v.c>u.c*v.b;//u.b/u.c>v.b/v.c也就是按照單位時間價值的減少量從大到小排序 
}//使分數減少快的先做! 
int dp[3005];
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",&mp[i].a,&mp[i].b,&mp[i].c);
		}
		sort(mp,mp+n,cmp);
		memset(dp,0,sizeof(dp));
		for(int i=0;i<n;i++)
		{
			for(int j=t;j>=mp[i].c;j--)
			{
				dp[j]=max(dp[j],dp[j-mp[i].c]+mp[i].a-j*mp[i].b);
			}
		}
		int ans=0;
		for(int i=0;i<=t;i++)//不一定是做最後一個得分最高 
		{
			ans=max(ans,dp[i]);
		}
		printf("%d\n",ans);
//		printf("%d\n",dp[t]); 
	}
	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章