2017 山东省赛 CF 傻瓜01背包
来源:互联网 发布:美术生 知乎 编辑:程序博客网 时间:2024/05/22 06:54
LYD loves codeforces since there are many Russian contests. In an contest lasting for T minutes there are n problems, and for the ith 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
The third line contains n integers d1,d2,..,dn.
The forth line contains n integers c1,c2,..,cn.
Output
Output an integer in a single line, indicating the maximum points LYD can get.
Example Input
3 10
100 200 250
5 6 7
2 4 10
Example Output
254
题意:给你每个题的初始 ai 分数 和 每分钟减少 di分数 和做这题需要 ci时间。
傻瓜01背包。。傻瓜背包加贪心。。以前接触过,一时没想起来。
权值是 di/ci 这个越小的越要首先选因为这个是负面的值。
然后就是普通的01背包。
不过需要知道的是 01背包的一个性质,越先选的再排序上要先放在后面。也可以理解为,最后一个一旦确定,整条路线都会已经确定。所以 把权值小的放在后面。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;int n,t;struct node{ int a,d,c; double f;}s[101010];int cmp(node a,node b){ return a.f>b.f;}int dp[101010];int main(){ while(cin>>n>>t) { for(int i=0;i<n;i++) cin>>s[i].a; for(int i=0;i<n;i++) cin>>s[i].d; for(int i=0;i<n;i++) { cin>>s[i].c; s[i].f=s[i].d*1.0/s[i].c; } int maxx=0; sort(s,s+n,cmp); memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++) { for(int j=t;j>=s[i].c;j--) { dp[j]=max(dp[j],dp[j-s[i].c]+s[i].a-s[i].d*j); maxx=max(maxx,dp[j]); } } printf("%d\n",maxx ); }}
- 2017 山东省赛 CF 傻瓜01背包
- 山东省第八届 ACM 省赛 CF (01背包、水)
- CF----思维排序+01背包 山东省第八届省赛K题
- 山东省第八届ACM省赛 K 题 CF (排序01背包)
- 山东省第八届ACM省赛K题 CF(01背包,技巧得排序)
- qduoj codeforces 山东省第八届acm省赛K题 CF (排序+01背包)
- 第八届山东省赛题->CF
- 第八届山东省赛 sdut 3903 CF(贪心+dp)
- 2017第八届浪潮杯山东省赛 K题 codeforces 贪心+背包
- 2017山东省赛总结
- 2017山东省赛 Fireworks
- cf B. Modulo Sum (01背包)
- CF gym Coins(01背包计数)
- CF Buns (01背包问题)
- 2017 ACM山东省赛 D
- 山东省赛
- 山东省第三届ACM大学生程序设计竞赛 Fruit Ninja I(01背包)
- 2017第八届山东省赛总结
- 人脸检测之Haar分类器方法
- vim c++开发环境配置2
- cms项目分析
- js原型链运行原理
- Java概念性问题6
- 2017 山东省赛 CF 傻瓜01背包
- MYSQL添加新用户 MYSQL为用户创建数据库 MYSQL为新用户分配权限
- Makefile 使用总结
- Linux常用命令学习(一)
- freemark 判断并截取字符长度
- 欧几里得算法及其拓展
- c# WinForm 同一个窗体只创建一次实例
- 模拟暴力 uva12108
- c++实现单链表创建,删除,遍历,插入,修改操作