山東省第八屆acm省賽K題 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

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:雖然不是很難,但是還是卡了一會,卡住的理由太弱智了,不提也罷+_+

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章