• ZOJ 3077 Move to Baggage Office


    逗比的A题技巧:


     图片


    Move to Baggage Office

    Time Limit: 1 Second      Memory Limit: 32768 KB

    watashi's mm is so pretty as well as clever. When she has to move to YQ from ZJG, she turns to watashi for help to move her baggages to the baggage office from her dormitory.

    Now watashi has initially total strength s. Because there are so many baggages, watashi may be unable to move all baggages to the baggage office. So, watashi decides to make a perfect plan to reduce the loss.

    Every baggage has three property values vab, that is

    • v: the value of this baggage
    • a: if watashi wants to move this baggage, the must have no less than a strength left. And if he moves this baggage to baggage office, he will loss a strength.
    • b: after watashi moves this baggage and walks back to dormitory, he can recover b strength.

    Now watashi is thinking how can he reduce the least loss, that is to make the total value of baggages in the baggage office largest. Can you help him?

    Input

    There are multiple cases, the first line contains an integer T, representing the number of test cases.

    The first line of each case is two integers, s and n. 10 <= s <= 1000 is the initial strength. 1 <= n <= 100 is the number of baggages.

    The next n lines represents the baggages, each line has three integers 0 <= vab <= 1000 and a > b.

    Output

    An integer V for each case representing the total value baggage that watashi can move to baggage office.

    Sample Input

    1
    9 3
    12 3 1
    13 3 1
    14 7 2

    Sample Output

    27
    Author: LI, Yaochun
    Source: ZOJ Monthly, December 2008




    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>

    using namespace std;

    struct node
    {
        int v,a,b,c;
    }kt[111];
    int s,n,dp[1111];

    bool cmp(node x,node y)
    {
           return x.b<y.b;
    }

    int main()
    {
        int T;
        scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&s,&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d%d%d",&kt.v,&kt.a,&kt.b);
            kt.c=kt.a-kt.b;
        }
        memset(dp,0,sizeof(dp));

        sort(kt,kt+n,cmp);

        for(int i=0;i<n;i++)
        for(int j=s;j>=kt.a;j--)
        {
            dp[j]=max(dp[j],dp[j-kt.c]+kt.v);
        }

        int sum=0;
        for(int i=0;i<=s;i++)
            sum=max(sum,dp);

        printf("%d ",sum);
    }
        return 0;
    }
    本地图片,请重新上传
  • 相关阅读:
    计算与软件工程 作业三
    计算与软件工程 作业二
    计算与软件工程 作业一
    计算与软件工程 作业六
    计算与软件工程 作业五
    计算与软件工程 作业四
    计算与软件工程 作业三
    计算与软件工程 作业二
    计算与软件工程 作业一
    第六次作业
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350928.html
Copyright © 2020-2023  润新知