山东省第八届ACM省赛 K 题 CF (排序01背包)
来源:互联网 发布:python获取当前日期 编辑:程序博客网 时间:2024/05/17 09:07
Problem Description
LYD loves codeforces since there are many Russian contests. In an contest lasting for T minutes there are n problems, and for theith problem you can get ai−di∗ti points, where ai indicates the initial points, di indicates the points decreased per minute (count from the beginning of the contest), and ti stands for the passed minutes when you solved the problem (count from the begining of the contest).
Now you know LYD can solve the ith problem in ci minutes. He can't perform as a multi-core processor, so he can think of only one problem at a moment. Can you help him get as many points as he can?
Input
The first line contains two integers n,T(0≤n≤2000,0≤T≤5000).
The second line contains n integers a1,a2,..,an(0<ai≤6000).
The third line contains n integers d1,d2,..,dn(0<di≤50).
The forth line contains n integers c1,c2,..,cn(0<ci≤400).
Output
Output an integer in a single line, indicating the maximum points LYD can get.
Example Input
3 10100 200 2505 6 72 4 10
Example Output
254
题意:LYD要打CF,一共n道题,t单位时间,每道题都有初始分数a,每单位时间减的分数d和做出这道题需要多长时间c,求最大的得分;
思路:这题不是跟以前的背包一样,这题后面选的每个东西都跟前面有关的。。前面的那种背包无关顺序,所以这种肯定要排个序,如果是无序的,这个最优过程中选的也不一定按照最优顺序的。。只是这种顺序的最优解,比如 11 1 1 ,11 1 10从前往后分别是11分, 1分钟做完,每秒掉1/10分,这也最优就是10分,第二个都成了0分,如果第一个在前面 就不一样了。。
然后按照怎样的顺序排序呢
假设有两个题, 第一个题 a.c a.d 第二个题 b.c b.d 两种顺序减得分分别是 a.c*a.d+(b.c+a.c)*b.d 〈 b.c*b.d+(b.c+a.c)*a.d 化简就是a.c/a.d < b.c/b.d
真的不想提省赛,这也是个套路题,比赛最后40分钟我背包,排序我都想到了,但没具体深想,然后就被队友叫去找规律了。。这是离金牌最近的一次,却出了事故,呵呵,之后的比赛加油!
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1e6 + 5;int dp[maxn];struct node{ int d, c, t; double f;}a[2000+5];int cmp(node a, node b){ return a.f < b.f;}int main(){ int n, t; while(~scanf("%d%d", &n, &t)) { memset(dp, 0, sizeof(dp)); for(int i = 1; i <= n; i++) scanf("%d", &a[i].t); for(int i = 1; i <= n; i++) scanf("%d", &a[i].d); for(int i = 1; i <= n; i++) scanf("%d", &a[i].c), a[i].f = a[i].c*1.0 / a[i].d; sort(a+1, a+1+n, cmp); int maxx = 0; for(int i = 1; i <= n; i++) { for(int v = t; v >= a[i].c; v--) { dp[v] = max(dp[v], dp[v-a[i].c]+a[i].t-a[i].d*v); maxx = max(dp[v], maxx); //在过程中取最大值,因为不一定t分钟都用上 } } printf("%d\n", maxx); } return 0;}
- 山东省第八届ACM省赛 K 题 CF (排序01背包)
- 山东省第八届ACM省赛K题 CF(01背包,技巧得排序)
- qduoj codeforces 山东省第八届acm省赛K题 CF (排序+01背包)
- CF----思维排序+01背包 山东省第八届省赛K题
- 山东省第八届 ACM 省赛 CF (01背包、水)
- 山东省第八届ACM省赛 K 题(CF)
- 山东省第八届acm省赛K题 CF
- 山东省第八届ACM省赛 K 题 CF 解答(未完,待续)
- 山东省第八届acm省赛K题 贪心+dp
- 山东省第八届ACM省赛C题
- 山东省第八届ACM省赛A题
- "浪潮杯”山东省第八届ACM大学生程序设计竞赛 CF
- 第八届山东省赛题->CF
- 山东省第八届acm省赛C题 巨坑
- 山东省第八届acm省赛A题 博弈
- 山东省第八届ACM省赛 I 题(Parity check)
- 山东省第八届ACM省赛 J 题(company)
- 山东省第八届ACM省赛 F 题(quadratic equation)
- js函数作用域及this指向
- mysqli使用预处理技术进行数据库查询的方法
- ZooKeeper 入门
- 做一个简单的太阳系(二)
- Maven介绍,包括作用、核心概念、用法、常用命令、扩展及配置
- 山东省第八届ACM省赛 K 题 CF (排序01背包)
- "<<"运算符的重载
- Maven
- 代码抽象
- 数组中包含对象的去重方法
- linux下rename命令的用法——适合大批量修改文件名
- WEB服务器如何选择 Apache or Nginx?
- OpenDaylight-Boron学习笔记: 3 L2Switch模块
- Swift 对象内存模型探究