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 10 100 200 250 5 6 7 2 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;
}