The Highest Mark
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 247 Accepted Submission(s): 101
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
题解:01背包问题。。。不过要预处理下,按照分数流失度从大到小排;
代码:
1 #include2 #include 3 #include 4 #include 5 #define MIN(x,y)(x y?x:y) 7 const int INF=0x3f3f3f3f; 8 using namespace std; 9 struct Node{10 int a,b,c;11 void in(){12 scanf("%d%d%d",&a,&b,&c);13 }14 friend bool operator <(Node a,Node b){15 return a.b*b.c>a.c*b.b;16 }17 };18 Node dt[1010];19 int bag[3010];20 int main(){21 int T,n,t;22 scanf("%d",&T);23 while(T--){24 scanf("%d%d",&n,&t);25 for(int i=0;i =dt[i].c;j--){32 bag[j]=MAX(bag[j],bag[j-dt[i].c]+dt[i].a-j*dt[i].b);33 }34 }35 int max=0;36 for(int i=0;i<=t;i++)max=MAX(max,bag[i]);37 printf("%d\n",max);38 }39 return 0;40 }
明知道暴力肯定超时,还是写了下;
1 #include2 #include 3 #include 4 #include 5 #define MIN(x,y)(x y?x:y) 7 const int INF=0x3f3f3f3f; 8 using namespace std; 9 int n,t,ans;10 int vis[1010];11 struct Node{12 int a,b,c;13 };14 Node dt[1010];15 void dfs(int time,int score){16 if(time>t)return;17 ans=MAX(ans,score);18 for(int i=0;i