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∗ti 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
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
题意 :
在时间范围内做出来题得到分数,每个题的分数是a-d*t,t包括从比赛第一分钟一直到此题做完的时间,求所得分数的最大值。
想法:
看题意觉得比较简单╮(╯_╰)╭
就是一道背包问题,但是对他排序的条件是比较巧妙的。
因为会掉分数,所以我们一定会选择单位时间内消耗分数最快的最先完成,即f=c/d;所以对其排序,之后按照01背包来做就好啦~
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int dp[5000];
struct init
{
int a,d,c;
double f;
} adj[5000];
bool cmp(init m,init n)
{
return m.f<n.f;
}//这下应该不会忘记结构体排序了吧QAQ
int main()
{
int n,t;
memset(dp,0,sizeof dp);
while(~scanf("%d%d",&n,&t))
{
for(int i=0; i<n; ++i)
cin>>adj[i].a;
for(int i=0; i<n; ++i)
cin>>adj[i].d;
for(int i=0; i<n; ++i)
{
cin>>adj[i].c;
adj[i].f=adj[i].c*1.0/adj[i].d;
}
sort(adj,adj+n,cmp);
int maxx=0;
for(int i=0; i<n; i++)
{
for(int v=t; v>=adj[i].c; v--)
{
dp[v] = max(dp[v], dp[v-adj[i].c]+adj[i].a-adj[i].d*v);
maxx = max(dp[v], maxx);
}
}
printf("%d\n",maxx);
}
return 0;
}
ps:虽然不是很难,但是还是卡了一会,卡住的理由太弱智了,不提也罢+_+