CF

Time Limit: 1000 msMemory Limit: 65536 KiB

Problem Description

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 aiditi 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.

Sample Input

3 10
100 200 250
5 6 7
2 4 10

Sample Output

254

Hint

Source

“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)

题意:在总时间T时间内,有n道题目,ai是第i道题目的分值,di是第i道题目,在单位时间内分数减少di,ci是第i道题目在ci时间内做完,题目让求的是在给定时间内,能够得到最多的分数(这就用到贪心的思想),最大的分数就是ai-di*ci(这是能够得到的最大分数),为了能够得到最大的分数,我们就要先做分数消耗最快并且解题需要时间最短的。例如:(两个题目A和B,如果先做A,那么丢失的分数就是ca*da+(ca+cb)*db,如果先做B,那么丢失的分数就是cb*db+(cb+ca)*da ,所以要丢失最少的分数,就要找di最大,并且ci最小的,那么这时就需要求di/ci的比值,如果比值大的话,就先做(证明di大ci小,其比值才会最大),如果比值小的话,就后做,这时就需要排序  )

思路:用结构体来存放a,d,c,f(比值),然后将按照从大到小的顺序进行排序,

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;
#define maxn  100010
long long int dp[maxn];
struct node{int a;int d;int c;double f;
}num[maxn];
bool compare(node a,node b)
{return a.f>b.f;
}
int main()
{int n,t;int i,j,k;scanf("%d%d",&n,&t);memset(dp,0,sizeof(dp));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);num[i].f=1.0*num[i].d/num[i].c;}sort(num,num+n,compare);for(i=0;i<n;i++){for(j=t;j>=num[i].c;j--){dp[j]=max(dp[j],dp[j-num[i].c]+num[i].a-j*num[i].d);// 做这个题目之前做的题目的分数加上这道题目的得分,然后与当前的分数比较,取最大的//cout<<"j = "<<j<<" dp[j] = "<<dp[j]<<endl;//      cout<<" dp[j-num[i].c] = "<<j-num[i].c<<endl; 在做这个题目之前做的题目,用现在的时间减去现在做的题目的时间,就是之前做的题目//     cout<<" j * num[i].d = "<<j * num[i].d<<endl; 丢失的分数    }}  long long  int result=0;//找最大的分数for(i=0;i<=t;i++){result=max(result,dp[i]);}printf("%lld\n",result);
}

CF 贪心+dp(动态规划) 01背包(做与不做)相关推荐

  1. 动态规划——01背包

    动态规划--01背包 1. 经典"01背包" 2. "01背包"方法归纳 3. 实战 3.1 分割等和子集 3.2 最后一块石头的重量 II 3.3 目标和 3 ...

  2. 贪心算法和01背包算法

    贪心算法和01背包算法 实验报告 1.问题 2.解析 3.设计 4.分析 5.源码 实验报告 课程名称 <算法分析与设计> 实验名称 贪心算法和01背包算法 1.问题 [描述算法问题,首选 ...

  3. 【HDU - 2546】饭卡 (dp,0-1背包,贪心思想)

    电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够).所以大家 ...

  4. 【UVA - 10154 】Weights and Measures (贪心排序,dp,类似0-1背包,状态设定思维)

    题干: The Problem Mack, in an effort to avoid being cracked, has enlisted your advice as to the order ...

  5. dp 动态规划 01背包问题 Python

    参考学习网址: https://www.bilibili.com/video/av33930433?from=search&seid=10637513335818789097 https:// ...

  6. 动态规划-----------01背包,完全背包与多重背包

    P01: 01背包问题 题目 有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].求解将哪些物品装入背包可使价值总和最大. 基本思路 这是最基础的背包问题,特点是:每种物品仅有 ...

  7. 【POJ - 3211】Washing Clothes (dp,0-1背包中点问题)

    题干: Dearboy was so busy recently that now he has piles of clothes to wash. Luckily, he has a beautif ...

  8. 【 POJ - 3628 】Bookshelf 2(dfs 或 dp,0-1背包)

    题干: Farmer John recently bought another bookshelf for the cow library, but the shelf is getting fill ...

  9. 【nyoj-456】 邮票分你一半 (dp,0-1背包的中点问题)

    题干: 邮票分你一半 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 小珂最近收集了些邮票,他想把其中的一些给他的好朋友小明.每张邮票上都有分值,他们想把这些邮票分成两份 ...

  10. 【蓝桥杯官网试题 - 算法提高 】求最大值 (dp,0-1背包)

    题干: 问题描述 给n个有序整数对ai bi,你需要选择一些整数对 使得所有你选定的数的ai+bi的和最大.并且要求你选定的数对的ai之和非负,bi之和非负. 输入格式 输入的第一行为n,数对的个数 ...

最新文章

  1. 关于css position和scroll事件的一些理解
  2. R语言因子转数值类型
  3. 发布可伸缩超网SCARLET,小米AutoML团队NAS三部曲杀青
  4. pack_padded_sequence 和 pad_packed_sequence
  5. android中OnItemClickListener的参数解释
  6. 【No.1 Ionic】基础环境配置
  7. linux下关闭网络服务,Linux 关闭网络管理服务
  8. Flutter中嵌入Android 原生TextView
  9. JVM学习笔记四_垃圾收集器与内存分配策略
  10. 穿越沙漠问题c语言算法,沙漠穿越问题_c语言课程设计.doc
  11. java 导出Excel 转图片地址为图片
  12. C++哈利波特代码(下)
  13. 学生信息表 成绩表+12章练习
  14. php 读doc_PHP读取DOC 文件
  15. Chap和pap认证
  16. kmalloc与vmalloc的区别
  17. U盘突然变为RAW格式
  18. 在机器学习中应用数学方法
  19. 摩拜单车服务器暂时不可用,摩拜单车无响应无法使用怎么回事?扫码解锁秒退解决方法...
  20. 数通工程师的前景怎么样?好就业吗?

热门文章

  1. R语言 数据操作小贴士合集
  2. 科学养生:揭秘世界上最健康的作息时间表
  3. 鸿雁牵手阿里打造智能家居平台
  4. 图算法设计之用普里姆Prim算法构造最小生成树
  5. 一、数据库之理论基础
  6. 用python画星空-用Python画一个超级月亮
  7. java编程题身高排队,试题 算法训练 预测身高
  8. 航天生物计算机作文,科幻遨游太空作文(精选6篇)
  9. [强烈推荐]ring0下文件解锁强制删除工具
  10. CSS 发明者 Håkon Wium Lie 访谈--csdn zhangxin09