CF
Time Limit: 1000 ms Memory Limit: 65536 KiB
https://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/3903.html
Submit Statistic Discuss
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
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大学生程序设计竞赛(感谢青岛科技大学)
【分析】
可以按01背包的思想计算。
但是状态转换方程很奇妙~!
dp[j]=max(dp[j], dp[j-e[i].c]+e[i].a-e[i].d*j)
与时间有关,时间过去的越多,罚掉的分越多,所以我们希望尽可能少的损失罚分。
因此,要先考虑掉分快的题,先挽留住。
排序,按掉分速度(d/c)从大到小。
【代码】
#include<bits/stdc++.h>
using namespace std;
const int N=2020;
struct node{
int a,d,c;
}e[N];
bool cmp(node r,node t){
return r.d*t.c>t.d*r.c;
}
int n,T,dp[5050];
int main()
{
cin>>n>>T;
for(int i=0;i<n;i++)scanf("%d",&e[i].a);
for(int i=0;i<n;i++)scanf("%d",&e[i].d);
for(int i=0;i<n;i++)scanf("%d",&e[i].c);
sort(e,e+n,cmp);
int ans=0;
for(int i=0;i<n;i++)
{
for(int j=T;j>=0;j--)if(j>=e[i].c)
{
dp[j]=max(dp[j],dp[j-e[i].c]+e[i].a-e[i].d*j);
ans=max(ans,dp[j]);
}
}
cout<<ans<<endl;
}