2017第八届浪潮杯山东省赛 K题 codeforces 贪心+背包
来源:互联网 发布:独立思考 知乎 编辑:程序博客网 时间:2024/06/07 00:26
codeforces
发布时间: 2017年5月13日 22:40 最后更新: 2017年5月14日 16:39 时间限制: 1000ms 内存限制: 128M
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 beginning 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 ashe can?
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 an integer in a single line, indicating the maximum points LYD can get.
3 10100 200 2505 6 72 4 10
254
第一次接触贪心加背包的题(巨弱。。。。。。一直写裸的01背包,还想不出来错,以为背包都可以跑出来。。。。。。。浪费了很长时间
举一个很简单的例子两个题目 AB,给定时间内都可以解决(T>=c1+c2),先解决A后解决B可以得到的分数是(a1-c1*d1+a2-(c1+c2)*d2),而先解决B后解决A可以得到的分数是(a1-(c1+c2)*d1+a2-c2*d2),两者不同的地方是 -c1*d2 -c2*d1 ,所以应该是d越大的越靠前,c越小的越靠前,这样首先根据d/c 的值排序,再背包
#include<bits/stdc++.h>using namespace std;struct node{ int a,d,c;}num[2005];int dp[5005];int cmp(node u,node v){ return u.c*v.d<v.c*u.d;}int main(){ int T,n,i,j; cin>>n>>T; for(i=0;i<n;i++) scanf("%d",&num[i].a); for(i=0;i<n;i++) scanf("%d",&num[i].d); for(i=0;i<n;i++) scanf("%d",&num[i].c); sort(num,num+n,cmp); int ans=0; for(i=0;i<n;i++) { for(j=T;j>=num[i].c;j--) { dp[j]=max(dp[j],dp[j-num[i].c]+max(num[i].a-num[i].d*j,0)); ans=max(ans,dp[j]); } } cout<<ans<<endl; return 0;}
- 2017第八届浪潮杯山东省赛 K题 codeforces 贪心+背包
- qduoj codeforces 山东省第八届acm省赛K题 CF (排序+01背包)
- 关于第八届浪潮杯(山东省赛)
- 山东省第八届acm省赛K题 贪心+dp
- 2017第八届浪潮杯山东省赛 A.Return of the Nim 博弈
- "浪潮杯”山东省第八届ACM大学生程序设计竞赛 CF
- "浪潮杯"第八届ACM山东省省赛青科场总结
- “浪潮杯”山东省第八届ACM大学生程序设计竞赛F
- “浪潮杯”山东省第八届ACM大学生程序设计竞赛G
- “浪潮杯”山东省第八届ACM大学生程序设计竞赛I
- “浪潮杯”山东省第八届ACM大学生程序设计竞赛 J
- CF----思维排序+01背包 山东省第八届省赛K题
- 第八届山东省赛题 J company (贪心,水)
- SDUT 2408 Pick apples(完全背包+贪心)2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛
- 山东省第八届ACM省赛 K 题 CF (排序01背包)
- 山东省第八届ACM省赛K题 CF(01背包,技巧得排序)
- 第八届山东省赛 sdut 3903 CF(贪心+dp)
- 第八届省赛K题(贪心+01背包)
- 最全三大框架整合(使用映射)——Dept.java
- 物体运动框架
- Shader案例篇二《镜子2》
- poj1474(半平面交)
- Android就业面试技巧系列-技术篇7 (ListView优化)
- 2017第八届浪潮杯山东省赛 K题 codeforces 贪心+背包
- Android中Notification使用及常用属性
- python3.4获取网站40x 50x错误并发邮件通知
- C语言趣味程序(13)
- 最全三大框架整合(使用映射)——Emp.java
- Handler实现Activity和Service通信
- JavaMail 之 搜索邮件
- Android就业面试技巧系列-技术篇8 (Volley框架)
- 微信小程序 RSA加密 解密 加签 验签