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∗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<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
题意:在总时间T时间内,有n道题目,ai是第i道题目的分值,di是第i道题目,在单位时间内分数减少di,ci是第i道题目在ci时间内做完,题目让求的是在给定时间内,能够得到最多的分数(这就用到贪心的思想),最大的分数就是ai-di*ci(这是能够得到的最大分数),为了能够得到最大的分数,我们就要先做分数消耗最快并且解题需要时间最短的。例如:(两个题目A和B,如果先做A,那么丢失的分数就是ca*da+(ca+cb)*db,如果先做B,那么丢失的分数就是cb*db+(cb+ca)*da ,所以要丢失最少的分数,就要找di最大,并且ci最小的,那么这时就需要求di/ci的比值,如果比值大的话,就先做(证明di大ci小,其比值才会最大),如果比值小的话,就后做,这时就需要排序 )
思路:用结构体来存放a,d,c,f(比值),然后将按照从大到小的顺序进行排序,
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;
#define maxn 100010
long long int dp[maxn];
struct node{
int a;
int d;
int c;
double f;
}num[maxn];
bool compare(node a,node b)
{
return a.f>b.f;
}
int main()
{
int n,t;
int i,j,k;
scanf("%d%d",&n,&t);
memset(dp,0,sizeof(dp));
for(i=0;i<n;i++)
{
scanf("%d",&num[i].a);
}
for(i=0;i<n;i++)
{
scanf("%d",&num[i].d);
}
for(i=0;i<n;i++)
{
scanf("%d",&num[i].c);
num[i].f=1.0*num[i].d/num[i].c;
}
sort(num,num+n,compare);
for(i=0;i<n;i++)
{
for(j=t;j>=num[i].c;j--)
{
dp[j]=max(dp[j],dp[j-num[i].c]+num[i].a-j*num[i].d);
// 做这个题目之前做的题目的分数加上这道题目的得分,然后与当前的分数比较,取最大的
//cout<<"j = "<<j<<" dp[j] = "<<dp[j]<<endl;
// cout<<" dp[j-num[i].c] = "<<j-num[i].c<<endl; 在做这个题目之前做的题目,用现在的时间减去现在做的题目的时间,就是之前做的题目
// cout<<" j * num[i].d = "<<j * num[i].d<<endl; 丢失的分数
}
}
long long int result=0;//找最大的分数
for(i=0;i<=t;i++)
{
result=max(result,dp[i]);
}
printf("%lld\n",result);
}