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\n",sum);
}
    return 0;
}
本地图片,请重新上传

转载于:https://www.cnblogs.com/CKboss/p/3350928.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值