SDUT 3903 CF【Dp+排序】
来源:互联网 发布:ubuntu 网络映射 编辑:程序博客网 时间:2024/06/05 11:27
CF
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 ai−di∗tipoints, 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
Hint
Author
题目大意:
一场时间长度为T的比赛,一共有N个题。
接下来一行表示每道题初始的分数,然后再下一行表示每一单位时间减少的分数。
最后一行输入表示做出来这道题需要的时长。
问最多能够获得多少分。
思路:
直接贪心肯定是不行的。
假设我们此时贪心出来一个做题顺序,使得减少的分数按照相对时间来讲最小。
那么我们直接按序模拟是不行的。
因为涉及到这样一点:当前题目做不做对后边是有影响的。一道题的分数高不高和做题时间都会对后边内容有所影响的。
所以我们现在如果有一个相对贪心的顺序之后,我们不妨看做时间为花费,得到的收益就是a【i】.val-a【i】.del*tottime.
那么这里做一个01背包就行。
那么考虑如何排序:
我们不能根据减小的速度来评判一个题是否有序,因为这一道题的时间也会影响下一个题的减少量。
所以我们排序应当按照单位时间来排序。
那么总结概述就是:按照题的单位时间减少分数从小到大排序,然后做一个01背包即可。
Ac代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct node{ int val,del,tim;}a[5500];int dp[70000];int cmp(node a,node b){ return (double)a.del/(double)a.tim>(double)b.del/(double)b.tim;}int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++)scanf("%d",&a[i].val); for(int i=0;i<n;i++)scanf("%d",&a[i].del); for(int i=0;i<n;i++)scanf("%d",&a[i].tim); sort(a,a+n,cmp); int output=0; for(int i=0;i<n;i++) { for(int j=m;j>=a[i].tim;j--) { dp[j]=max(dp[j],dp[j-a[i].tim]+a[i].val-a[i].del*j); } } for(int i=0;i<=m;i++)output=max(output,dp[i]); printf("%d\n",output); }}
- SDUT 3903 CF【Dp+排序】
- 第八届山东省赛 sdut 3903 CF(贪心+dp)
- CF-SDUT-3360-
- CF 417D Cunning Gena [状压dp+排序]
- sdut 1309 区间DP
- SDUT排序问题
- SDUT 1591 交叉排序
- SDUT 3437 排序算法
- <sdut-ACM>交叉排序
- 排序 (sdut oj)
- 排序问题 (sdut oj)
- 字符串排序 (sdut oj)
- sdut acm 插入排序
- SDUT-1196 排序问题
- SDUT-1201 字符串排序
- sdut 字符串排序
- SDUT 2140-拓扑排序
- SDUT 1591 交叉排序
- 第二届CCCC天梯赛决赛总结
- W2.1 MySQL5.7 编译安装
- Android函数调用顺序库——AppMethodOrder使用介绍
- java微信公众号-第二天
- 读C++Primer的一点发现
- SDUT 3903 CF【Dp+排序】
- android集成二维码扫描
- 【微机实验系列】汇编语言和DOS系统
- [HDU]HDOJ1166 敌兵布阵 基础线段树
- 全速USB和高速USB的识别过程分析
- 搭建VPN
- github+jekyll搭建个人静态博客
- 学习笔记:wampserver提示You don't have permission to access/on this server.
- 感谢一些事情带来的启示