hdoj 5501 The Highest Mark 【贪心 + 0-1背包】
2015-10-11 17:07
387 查看
The Highest MarkTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 324 Accepted Submission(s): 129 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 |
思路:以为就是0-1背包,没想到测试数据都不过,加个贪心预处理一下就ok了。对于每道题,可选择做或不做,得到状态转移方程dp[j] = max(dp[j], dp[j-num[i].C] + num[i].A - j*num[i].B) (0 <= j <= m)。
AC代码:
#include <cstdio> #include <cstring> #include <algorithm> #define MAXN 3000+10 #define INF 0x3f3f3f3f using namespace std; int dp[MAXN]; struct rec{ int A, B, C; }; rec num[1010]; bool cmp(rec a, rec b){ return a.B * b.C > a.C * b.B; } int main() { int t; scanf("%d", &t); while(t--) { int n, m; scanf("%d%d", &n, &m); for(int i = 0; i < n; i++) scanf("%d%d%d", &num[i].A, &num[i].B, &num[i].C); sort(num, num+n, cmp); memset(dp, 0, sizeof(dp)); for(int i = 0; i < n; i++) for(int j = m; j >= num[i].C; j--) dp[j] = max(dp[j], dp[j-num[i].C] + num[i].A - j * num[i].B); int ans = 0; for(int i = 0; i <= m; i++) ans = max(dp[i], ans); printf("%d\n", ans); } return 0; }
相关文章推荐
- hdoj 5500 Reorder the Books 【好题】
- rhel7 设置带sgid的目录权限
- watchOS开发——Notification介绍
- lodop打印基本设置与简单使用
- LeetCode36:Valid Sudoku
- lodop打印基本设置与简单使用
- hdoj 5499 SDOI 【拼手速】
- Gson解析JSON中动态未知字段key的方法
- sicily 1063. Who's the Boss
- 提升Powershell的启动速度
- Intent有可能的使用(两)
- iOS 新浪微博-3.0 新特性
- android 数字选择器中文字颜色透明度渐变的实现
- ZOJ月赛10,11,第二个
- HDOJ 1848 Fibonacci again and again(sg函数模板,打表)
- 岛上书店
- 操作系统学习5
- linux C之access函数(转载)
- B-codeforces558B-Amr and The Large Array
- 关于k-均值算法