SDUT 3903 CF【Dp+排序】

来源:互联网 发布:ubuntu 网络映射 编辑:程序博客网 时间:2024/06/05 11:27

CF

Time Limit: 1000MS Memory Limit: 65536KB
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 aiditipoints, 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

Hint

Author

“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)

题目大意:

一场时间长度为T的比赛,一共有N个题。

接下来一行表示每道题初始的分数,然后再下一行表示每一单位时间减少的分数。

最后一行输入表示做出来这道题需要的时长。

问最多能够获得多少分。


思路:


直接贪心肯定是不行的。

假设我们此时贪心出来一个做题顺序,使得减少的分数按照相对时间来讲最小。

那么我们直接按序模拟是不行的。

因为涉及到这样一点:当前题目做不做对后边是有影响的。一道题的分数高不高和做题时间都会对后边内容有所影响的。


所以我们现在如果有一个相对贪心的顺序之后,我们不妨看做时间为花费,得到的收益就是a【i】.val-a【i】.del*tottime.

那么这里做一个01背包就行。


那么考虑如何排序:

我们不能根据减小的速度来评判一个题是否有序,因为这一道题的时间也会影响下一个题的减少量。

所以我们排序应当按照单位时间来排序。


那么总结概述就是:按照题的单位时间减少分数从小到大排序,然后做一个01背包即可。


Ac代码:

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct node{    int val,del,tim;}a[5500];int dp[70000];int cmp(node a,node b){    return (double)a.del/(double)a.tim>(double)b.del/(double)b.tim;}int main(){    int n,m;    while(~scanf("%d%d",&n,&m))    {        memset(dp,0,sizeof(dp));        for(int i=0;i<n;i++)scanf("%d",&a[i].val);        for(int i=0;i<n;i++)scanf("%d",&a[i].del);        for(int i=0;i<n;i++)scanf("%d",&a[i].tim);        sort(a,a+n,cmp);        int output=0;        for(int i=0;i<n;i++)        {            for(int j=m;j>=a[i].tim;j--)            {                dp[j]=max(dp[j],dp[j-a[i].tim]+a[i].val-a[i].del*j);            }        }        for(int i=0;i<=m;i++)output=max(output,dp[i]);        printf("%d\n",output);    }}













0 0
原创粉丝点击