关于贪心思想与DP的结合的几点认识
来源:互联网 发布:windows 画图命令 编辑:程序博客网 时间:2024/05/20 06:49
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
这道题是处理花费时间与递减时间的除数,然后根据除数排序,然后就是裸的背包。根据除数排序我能理解,就是有的题目你越早做损失的分数就越少,然后我们就按这个顺序来做题,但这样做题肯定是不对的,为什么呢?因为每道题的初始分值是不一样的,有的排完序之后虽然靠后,也就意味着可能在有限的时间里不会被选到,但这道题的初始分却很高,选择这道题的的分数比按顺序得到的分数要高,那么这就出问题了。所以这就需要我们重新来考虑一下这道题的做法了。然后我想了很久也没想明白,排不排序似乎对DP过程没什么影响啊!!!可能是我做题做的太少思考不到位的缘故吧,以后留着思考。
【tyvj1048】田忌赛马
题目描述
输入
输出
样例输入
样例输出
我之所以把这两道题归结在一起,是觉得这都是用了贪心来优化DP
#include<iostream>#include<cstring>#include<algorithm>using namespace std;int f[3001][3001],a[3001],b[3001],c[3001][3001];int n,ans=0;bool gz(int a,int b) {return a>b;}int main(){ cin>>n; for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) f[i][j]=-999999; for(int i=1;i<=n;i++)cin>>a[i]; for(int i=1;i<=n;i++)cin>>b[i]; sort(a+1,a+n+1,gz); sort(b+1,b+n+1,gz); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(a[i]>b[j])c[i][j]=1; else if(a[i]==b[j])c[i][j]=0; else c[i][j]=-1; f[0][0]=0; for(int i=1;i<=n;i++) for(int j=0;j<=i;j++) if(j>=1)f[i][j]=max(f[i-1][j]+c[n-(i-j)+1][i],f[i-1][j-1]+c[j][i]); else f[i][j]=f[i-1][j]+c[n-(i-j)+1][i]; for(int i=0;i<=n;i++) ans=max(f[n][i],ans); cout<<ans*200; return 0;}
- 关于贪心思想与DP的结合的几点认识
- 关于STRUCT的几点认识
- 关于C/C++的几点认识
- 关于thread的几点认识
- 关于UICollectionView的几点认识
- 关于红黑树的几点概念认识
- 关于web service的几点认识
- 关于CSS的几点认识
- 关于CABAC的几点认识
- 关于物理内存的几点认识
- 关于vc++中的坐标转换的几点认识
- 关于cgi和fastcgi的几点认识
- 关于四参数和七参数的几点认识
- 关于Android 权限管理的几点认识
- 关于大数据学习第一天的几点认识
- 关于computer view(CV)的几点认识-数字图像处理
- 多线程的几点认识
- ExecutorCompletionService 的几点认识
- Swift3.0 字符串
- 使用ToggleButton按钮实现的灯泡开关效果
- 自动内存管理机制
- 多线程知识巩固(八) 异步,同步
- LintCode-中位数
- 关于贪心思想与DP的结合的几点认识
- 关于android studio项目构建时产生各种问题的解决方法
- hrbust 2153 凸多边形的划分 (数论)
- Codeforces812C Sagheer and Nubian Market
- 基础数学公式 长期更新
- MySQL语句整理(1)
- 抽屉原理
- 内部类学习笔记
- MySQL语句整理(2)